Reputation: 51
R = [(1, 2,3,4), (1, 3), (1, 4), (1,4, 5), (1, 6), (2, 3), (2, 4), (2, 5), (2, 6), (3, 4), (3, 5), (3, 6), (4, 5), (4, 6), (5, 6)]
From the above set i just want to minus off the index or any values from the each element of the tuple.
And the expected answer would be
#R = [(1-0, 2-0,3-0,4-0), (1-1, 3-1), (1-2, 4-2) and so on
here is my code but i want it in a simplest way pls help
final_matches = {k: v for k,v in matches.items() if len(v) >= 4}
for k, v in matches.items():
if len(v) >= 3:
print(k,':',v,'/',len(v))
#for j in range(0,len(v)):
#print(v[j])
Upvotes: 0
Views: 274
Reputation: 51
v[:] = [x - k for x in v]
can do this when you iterate through the dict.
Upvotes: 0
Reputation: 71451
You can try this:
R = [(1, 2,3,4), (1, 3), (1, 4), (1,4, 5), (1, 6), (2, 3), (2, 4), (2, 5), (2, 6), (3, 4), (3, 5), (3, 6), (4, 5), (4, 6), (5, 6)]
new_list = [tuple(c-i for c in a) for i, a in enumerate(R)]
to get only tuples with length three:
new_list = [i for i in new_list if len(i) >= 3]
Final output:
[(1, 2, 3, 4), (-2, 1, 2)]
Upvotes: 1