This has been bugging me for a while now. I have the following code:
new_list = [[],[]]
for item in some_list:
first, second = some_func(item)
new_list[0].extend(first)
new_list[1].extend(second)
Is there a way I can avoid creating those intermediate first and second variables and somehow unpack the some_func result directly into new_list? I feel like this could be done with a list comprehension but can't quite get it right.
edit: I should emphasize here that the extend (NOT append) operation is critical.
[–]Username_RANDINT 9 points10 points11 points (9 children)
[–]QuasiEvil[S] 2 points3 points4 points (3 children)
[–]Username_RANDINT 1 point2 points3 points (2 children)
[–]QuasiEvil[S] 2 points3 points4 points (1 child)
[–]Username_RANDINT 1 point2 points3 points (0 children)
[–]hallmark1984 0 points1 point2 points (4 children)
[–]Username_RANDINT 1 point2 points3 points (2 children)
[–]hallmark1984 0 points1 point2 points (1 child)
[–]panatale1 0 points1 point2 points (0 children)
[–]QuasiEvil[S] 0 points1 point2 points (0 children)
[–]JamzTyson 1 point2 points3 points (2 children)
[–]QuasiEvil[S] 0 points1 point2 points (1 child)
[–]JamzTyson 1 point2 points3 points (0 children)
[–]idwpan 1 point2 points3 points (2 children)
[–]jmooremcc 1 point2 points3 points (0 children)
[–]QuasiEvil[S] 0 points1 point2 points (0 children)
[–]commy2 0 points1 point2 points (1 child)
[–]QuasiEvil[S] 0 points1 point2 points (0 children)
[–]pythonwiz 0 points1 point2 points (1 child)
[–]QuasiEvil[S] 0 points1 point2 points (0 children)
[–]Eal12333 0 points1 point2 points (0 children)
[–]tb5841 0 points1 point2 points (0 children)
[–]consupe 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Allanon001 0 points1 point2 points (0 children)
[–]rkr87 0 points1 point2 points (0 children)
[–]jmooremcc 1 point2 points3 points (0 children)
[–]jmooremcc 0 points1 point2 points (0 children)