0

Python: How do I get a certain digit of an element in a list?

For example i have a list of numbers of different length: a = ['3245', '678904', '879654'] How do I get, say, third digit of an element with index 1? As with strings we can get a certain symbol by it's index: x = 'apple' print(x[2]) >>>p But can I do it with a list element without introducing any other variables? It should look something like this: a = ['3245', '678904', '879654'] print(str(a[1])[2]) >>>8 I hope I've delivered my thought clearly :)

22nd Feb 2020, 8:20 PM
Arsenii Velichko
1 Respuesta
+ 2
Yeah, you can just double-index. print(str[1][2])
22nd Feb 2020, 8:22 PM
HonFu
HonFu - avatar