I need to get a sublist called invalids
from another list called opened_list
that pulls the records containing the value 12
along with their index in the list. I have tried the below code
x = opened_list
print (x.index(-1))
I want the output to be something like
a=[1,12,3,4,12,5,12]
b=[]
for idx,item in enumerate(a):
if item==12: b.append((idx,item))
print(b)
prints: [(1, 12), (4, 12), (6, 12)]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.