User Tools

Site Tools


How to use join with lists with integers

Suppose that we have a list such:

our_list = [1, 4, 5, 8]

Using “, ”.join(our_list) will not work because join expects strings and not integers.
TypeError: sequence item 0: expected string, int found


", ".join([str(elem) for elem in our_list])

or even easier (and more pythonic) :P

", ".join(map(str, our_list))

python/joinintlist.txt · Last modified: 2013/03/16 17:41 (external edit)