Skip to content
Advertisement

Perform a list comprehension inside of a for loop in Python [closed]

In short what I need is to get for each element from this set uniqueFiles = {volcano_021, opencountry_test_017, opencountry_test_017} get the element of index 1 from each nested array in which the index 0 is equal to the element of uniqueFiles set which will be iterating.

For instance consider the followin list:

JavaScript

What I was trying to do is through a for loop get the following result for such a loop

JavaScript

I came up with the following code…However it is not working.

I would like to do that using a list comprehension

JavaScript

Advertisement

Answer

You don’t need enumerate:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement