Convert a list to a list of 2 tuples
3 answers
Use a simple list comprehension for this:
>>> your_list = [1, 2, 3]
>>> x = 100
>>> your_list_with_tuples = [(k, x) for k in your_list]
>>> your_list_with_tuples
Output
[(1, 100), (2, 100), (3, 100)]
Also, don't name variables list
, dict
etc., because they hide built-in types / functions.
+10
source to share