So I got a list in python like this:
[1,2,3,4]
And I want the combinations between the number 3 with every number something like this:
[(1,3),(2,3),(3,4)]
Is there something I can use? I know there is something called itertools, but I'm kinda new so i'm not sure how to use it.
Thank you!
You might want to use a list comprehension:
orig_list = [1,2,3,4]
[(entry, 3) for entry in orig_list if entry != 3] # [(1, 3), (2, 3), (4, 3)]
If you're not interested in duplicate values you can make it into a set:
orig_list = set([1,2,3,4])
[(entry, 3) for entry in orig_list if entry != 3] # [(1, 3), (2, 3), (4, 3)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With