0

How do loop and get the first character of every element in a python list.

Let's say i have a list: mylist = ["apples", "bananas", "mangos"] I know that print(mylist[0][0]) will return the first character of first element ("a"). Now how do i write a loop that will iterate over all elements, and return there first characters. Output should be = "a" , "b", "m"

27th May 2021, 3:23 PM
David Holmes Ng'andu
David Holmes Ng'andu - avatar
3 Réponses
+ 4
for i in myList: print(i[0],end=",")
27th May 2021, 3:36 PM
TOLUENE
TOLUENE - avatar
0
Travon I already know that i can do that, but i need a loop to run over the whole element. Example: for i in mylist: print(i) This will return every element separately
27th May 2021, 3:29 PM
David Holmes Ng'andu
David Holmes Ng'andu - avatar
- 3
I think you should go with this Mylist([0][0][1][0][2[0])
27th May 2021, 3:26 PM
Travon
Travon - avatar