-3

There has a list A['a','b','c'] another struct B,
How to use A get below fommat?

B[A[0]][A[1]][A[2]]

andylei
  • 53
  • 2
  • Did you mean `A = ['a', 'b', 'c']`? Also, what do you mean struct B? I'm not sure I understand your operation `B[A[0]][A[1]][A[2]] ` – Skam Jun 14 '19 at 01:14
  • Not everyone's English is perfect, but you should at least try to write a clear example and try to make clear what your problem is exactly. What is `B`? What do you need exactly? – Grismar Jun 14 '19 at 01:15
  • Are you looking for the following? `A = ['a', 'b', 'c']; B = list(map(list, A)); print(B)` result `[['a'], ['b'], ['c']]` – Andrew Allen Jun 14 '19 at 01:20

2 Answers2

1

You can also do:

>>> A = ['a', 'b', 'c']
>>> B = list(map(lambda x: [x], A))
>>> B
[['a'], ['b'], ['c']]
>>> 
U13-Forward
  • 69,221
  • 14
  • 89
  • 114
0

Per comment OP was looking for:

A = ['a', 'b', 'c']
B = list(map(list, A))
print(B)

Result

[['a'], ['b'], ['c']]

This could also be achieved with list comprehension, though this is more verbose.

[[x] for x in A]
Andrew Allen
  • 6,512
  • 5
  • 30
  • 73