1

Suppose I have a (binary) string with length n. My goal is to assign the values of each element of the string to n variables: m_1, m_2, ..., m_n. I can do that when n is fixed: m_1, m_2, m_3 ,m_4, m_5 = map(int, '10110').

However, I don't know how I can do that dynamically, to accommodate an arbitrary n. I thought about using a list comprehension, but still not sure how it works to solve this problem.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
ZR-
  • 809
  • 1
  • 4
  • 12
  • 1
    Does this answer your question? [How do I create variable variables?](https://stackoverflow.com/questions/1373164/how-do-i-create-variable-variables) - `m = list(map(int, '10110'))`, then use `m[0]`, `m[1]`, `m[2]`, etc. An equivalent list comprehension would be `m = [int(x) for x in '10110']`. – mkrieger1 Nov 07 '21 at 18:04

0 Answers0