-3

I have this array "m":

m = ['0000', '0001', '0010', '0011', '1111']

How could I use a lambda function to change its format to:

n1 = [0,0,0,0,0,0,0,1,0,0,1,0,0,0,1,1,1,1,1,1]

or to:

n2 = [[0,0,0,0],[0,0,0,1],[0,0,1,0],[0,0,1,1],[1,1,1,1]]

?

3
  • [int(x) for x in '12345'] will get you the inner array. Commented Nov 21, 2018 at 22:02
  • You can create n2 with list comprehensions: n2 = [[int(char_i) for char_i in char] for char in m] Commented Nov 21, 2018 at 22:09
  • n0 = [list(item) for item in m]; n1 = [int(i) for lst in n0 for i in lst]; n2 = [[int(i) for i in lst] for lst in n0] Commented Nov 21, 2018 at 22:17

1 Answer 1

0
m = ['0000', '0001', '0010', '0011', '1111']
funct = lambda m: [int(x) for x in ''.join(m)];

This will express list "m" as list "n1" with a lambda function as requested.

Sign up to request clarification or add additional context in comments.

3 Comments

Could I do it without loop? Maybe lambda function
n1 = [int(x) for x in ''.join(m)]
funct = lambda m: [int(x) for x in ''.join(m)];

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.