0

Strings in arrays

Does anyone know how to print the first letter of each string in an array?

25th Feb 2021, 6:13 PM
Fazz Reaper
Fazz Reaper - avatar
3 odpowiedzi
+ 1
This task is language dependent, so specify relevant language in the thread's tags above ☝
25th Feb 2021, 6:20 PM
Ipang
+ 1
in almost languages arrays (lists in python built-ins) each elements is accessible trough square brackets notation... as string are almost character array, you could also access each char through square brackets... so you need a loop to iterate over string array, and output only the character at index 0 of each string: str_item[0] Fazz Reaper edit: with i as the array index: str_array[i][0]
25th Feb 2021, 6:38 PM
visph
visph - avatar
0
In python import numpy as np name = np.array(["sinam", "tashi", "somi"]) for i in name: print(i[0], end="")
25th Feb 2021, 6:27 PM
Sonam Tashi