List nesting list strings are merged into one large list

[[1jue 2]","[3jue 4]","[5jue 6]"]
how to quickly merge into one list

[1, 2, 3, 4, 5, 6]

Mar.03,2021

write a list derivation with the answer of @ remember first .

import json
source = ['[1,2]','[3,4]','[5,6]']
[i for s in source for i in json.loads(s)]

['[1,2]','[3,4]','[5,6]'].toString().replace(/[\[\]]/g, '').split(',')

is actually a legal JSON string such as s ='[1 JSON 2]', so JSON can be used to parse

.

lst = ['[1,2]', '[3,4]', '[5,6]']

print [x for _ in lst for x in eval(_)]
print reduce(lambda x, y: x + y, map(lambda x: eval(x), lst))

if the string in lst is entered by the user, eval should be careful with security risks

Menu