Print First Character of Each List in Python



Assuming that the list is collection of strings, the first character of each string is obtained as follows −

>>> L1=['aaa','bbb','ccc']
>>> for string in L1:
print (string[0])

a
b
c

If list is a collection of list objects. First element of each list is obtained as follows −

>>> L1=[[1,2,3],[4,5,6],[7,8,9]]
>>> for list in L1:
print (list[0])

1
4
7
Updated on: 2020-06-18T13:35:47+05:30

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements