Easiest Way To Join List Of Ints In Python?
What is the most convenient way to join a list of ints to form a str without spaces? For example [1, 2, 3] will turn '1,2,3'. (without spaces). I know that ','.join([1, 2, 3]) woul
Solution 1:
','.join(str(x) for x in ints)
should be the most Pythonic way.
Solution 2:
print','.join(map(str,[1, 2, 3])) #Prints: 1,2,3
Mapping str prevents the TypeError
Post a Comment for "Easiest Way To Join List Of Ints In Python?"