Reputation: 6009
What is the most convenient way to join a list of int
s 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])
would raise a TypeError.
Upvotes: 3
Views: 3094
Reputation: 38237
','.join(str(x) for x in ints)
should be the most Pythonic way.
Upvotes: 6
Reputation: 310069
I like ','.join(str(i) for i in lst)
, but it's really not much different than map
Upvotes: 3
Reputation: 16240
print ','.join(map(str,[1, 2, 3])) #Prints: 1,2,3
Mapping str prevents the TypeError
Upvotes: 5