Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easiest way to join list of ints in Python?

Tags:

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]) would raise a TypeError.

like image 699
adamsmith Avatar asked Dec 08 '25 19:12

adamsmith


1 Answers

print ','.join(map(str,[1, 2, 3])) #Prints: 1,2,3

Mapping str prevents the TypeError

like image 91
Dair Avatar answered Dec 11 '25 10:12

Dair



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!