-1

What would be an easy way to convert:

(1,0,0,0,0,0)

to

['100000']

I know how to switch it to a list using

list()

but i can't figure out how to combine the elements into a string and keep that inside a list.

1 Answers1

0

sep.join(strlist) joins a list of strings together using sep as a separator.

In this case, you will have three steps:

  1. Convert the list of ints to a list of strs, which can be accomplished like so: strlist = map(str, intlist)
  2. Convert the list of strings to a single string using join. intstring = "".join(strlist)

    Setting the separator = "" will make it squish together to a single string.

  3. Convert the string to a list with a string: final = [intstring]

Or in one line, as in falsetru's comment:

[''.join(map(str, digits))]

reem
  • 7,186
  • 4
  • 20
  • 30