Loop through the list
There is a list with this structure:
[('Броня', [2, 0.6747547826210327])]
How can you loop through it, but at the same time, you need ('Броня', [2, 0.6747547826210327])
to be considered as a single element, and in the loop you can interact by type data[0], #Броня data[1] #[2, 0.6747547826210327]
My attempt was not successful, it goes through each one separately.
0
2 answers
We need a simple loop for
. For example:
lst = [('Броня', [2, 0.6747547826210327])]
for data in lst:
print(data[0], 'с характеристиками', data[1])
3
Author: Elusha, 2020-08-17 13:17:07
Idiomatic list traversal in python:
array = [('Броня1', [2, 0.6747547826210327]), ('Броня2', [2, 0.6747547826210327]), ('Броня3', [2, 0.6747547826210327])]
for armor in array:
print(armor[0], armor[1])
Output:
Броня1 [2, 0.6747547826210327]
Броня2 [2, 0.6747547826210327]
Броня3 [2, 0.6747547826210327]
2
Author: Ildar, 2020-08-17 14:09:07