How to convert a list elements to list of two values tuples in Python

1 Answer

0 votes
from itertools import repeat 
   
lst = [8, 4, 7, 6, 2, 9, 5, 3] 
   
ch = 'X'
   
result = list(zip(lst, repeat(ch))) 
   
print(str(result)) 
 
 
'''
run:
 
[(8, 'X'), (4, 'X'), (7, 'X'), (6, 'X'), (2, 'X'), (9, 'X'), (5, 'X'), (3, 'X')]
 
'''

 



answered Dec 15, 2019 by avibootz
edited Dec 15, 2019 by avibootz
...