I would like to convert an array of int (like this [1, 1, 2, 1]) into a string ("1121").
What’s the best (most pythonic) way to do this?
I could always do something like this then remove the extra brackets:
>>> str([1, 2, 1, 1])
'[1, 2, 1, 1]'
or I can do something like this:
s = ""
for i in [1, 2, 1, 1]:
s += s(i)
But both methods feel a little shaky. Is there a better way to do it?
For the record, I’m naturally interested in all versions of Python, but I’m working on py2.7 and would prefer answers that work with this version.
A generator expression:
PS: your “array” is really a list.