Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I have two lists,

In the first list I have all the information:

list1 = ['node1=6d', 'node2=10d', 'node3=5d']

In the second I just have the days:

list 2 = [6, 10, 5]

Is there a way to take the position from the indexes of the second one, which is <=7? (For example) and then print those with the same position of the list1?

Example:

Values of list2 that are <= 7:

Position 0, 2

Then print from list one those values with position 0, 2

Output should be:

['node1=6d', 'node3=5d'] 

1 Answer

0 votes
by (36.8k points)

from operator import itemgetter

idx = [i for i, n in enumerate(list2) if n <= 7]

result = itemgetter(*idx)(list1)

print(result)

('node1=6d', 'node3=5d')

 If you are a beginner and want to know more about Data Science the do check out the Data Science course

Browse Categories

...