E
Knowing the number index, you can follow the list by adding all the numbers to the list:lst = []
for x in price:
lst.append(int(x[1]))
And if you don't know, you need to add an additional check:lst = []
for x in price:
for j in x:
if j.isdigit():
lst.append(int(j)) # если работаете или нужны числа с плавающей точкой, то float(j)
So on the list. lst You'll need the data.If you're just gonna change the list, you need to use the design. list comprehension:One list with all the data where the numbers are already converted to type int:price = [['MOSCOW-LONDON:', '120', 'EUR'], ['LONDON-NEWYORK:', '235', 'USD'],
['NEWYORK-BRASILIA:', '112', 'BRL'], ['BRASILIA-PEKING:', '243', 'CNY'],
['PEKING-SEOUL:', '97', 'KRW'], ['SEOUL-DELHI:', '130', 'INR'],
['DELHI-MOSCOW:', '19526', 'RUB']]
price = [int(y) if y.isdigit() else y for x in price for y in x]
print(price)
['MOSCOW-LONDON:', 120, 'EUR', 'LONDON-NEWYORK:', 235, 'USD', 'NEWYORK-BRASILIA:', 112, 'BRL', 'BRASILIA-PEKING:', 243, 'CNY', 'PEKING-SEOUL:', 97, 'KRW', 'SEOUL-DELHI:', 130, 'INR', 'DELHI-MOSCOW:', 19526, 'RUB']
This current size can be maintained and the number of:price = [['MOSCOW-LONDON:', '120', 'EUR'], ['LONDON-NEWYORK:', '235', 'USD'],
['NEWYORK-BRASILIA:', '112', 'BRL'], ['BRASILIA-PEKING:', '243', 'CNY'],
['PEKING-SEOUL:', '97', 'KRW'], ['SEOUL-DELHI:', '130', 'INR'],
['DELHI-MOSCOW:', '19526', 'RUB']]
length = len(price)
for x in range(length):
= [int(y) if y.isdigit() else y for y in price[x]]
print(price)
[['MOSCOW-LONDON:', 120, 'EUR'], ['LONDON-NEWYORK:', 235, 'USD'], ['NEWYORK-BRASILIA:', 112, 'BRL'], ['BRASILIA-PEKING:', 243, 'CNY'], ['PEKING-SEOUL:', 97, 'KRW'], ['SEOUL-DELHI:', 130, 'INR'], ['DELHI-MOSCOW:', 19526, 'RUB']]