Zip() In Python, How To Use Static Values
I'm trying to build an array of tuples with first value from list with some static values. It should be simple but I'm struggling to do this for some reason. For example, how do I
Solution 1:
You could use itertools.repeat
to repeat the elements that you're trying to zip together.
>>>import itertools>>>zip([1, 2, 3, 4, 5], itertools.repeat(100), itertools.repeat(200))
[(1, 100, 200), (2, 100, 200), (3, 100, 200), (4, 100, 200), (5, 100, 200)]
You could also specify the number of times you need to repeat the element. (5 in this case)
Post a Comment for "Zip() In Python, How To Use Static Values"