Answer the question
In order to leave comments, you need to log in
How to output a list with one tuple of three, in which the list consists of even numbers?
There is a list with tuples, blackjack and... numbers
l = [("a", [1, 3, 5, 6, 7]), ("b", [1, 2, 3, 4, 5]), ("c", [2, 4, 6, 8])]
[("c", [2, 4, 6, 8])]
for i in range(len(l)):
for k in range(len(l[i][1])):
if l[i][1][k] % 2 != 0:
break
else:
if k == len(l[i][1]) - 1:
l = [l[i]]
print(l)
Answer the question
In order to leave comments, you need to log in
If it means that all elements are even, then mb is something like ..
l = [("a", [1, 3, 5, 6, 7]), ("b", [1, 2, 3, 4, 5]), ("c", [2, 4, 6, 8])]
def func(l):
for x in l:
if all(not i%2 for i in x[1]):
return x
print(func(l))
for x in l:
if len(x[1]) %2 ==0:
print(x)
or:s = [x for x in l if len(x[1]) %2 == 0 ]
print(s)
I always write bad code, but this is what I would do.
l = [("a", [1, 3, 5, 6, 7]), ("b", [1, 2, 3, 4, 5]), ("c", [2, 4, 6, 8]), ("g", [2, 3, 6, 8])]
A = []
for SAS in l:
Q = True
for SUS in SAS[1]:
if SUS % 2 != 0:
Q = False
break
if Q == True:
A.append(SAS[0])
print(A)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question