0

I have [1,2],[5],[2,7,9] and I want to make [[1,2],[5],[2,7,9]]. I tried some commands but they all return [1,2,5,2,7,9].

Can someone help?

Thanks

2
  • I see some lists? What exactly are you doing? Vague word descriptions leave us guessing. Commented May 28, 2021 at 0:17
  • What were the commands that you tried? Commented May 28, 2021 at 3:06

1 Answer 1

1
l1 = [1,2]
l2 = [5]
l3 = [2,7,9]

new_list = []
new_list = [l1] + [l2] + [l3]
print(new_list)
# or 
new_list = []
new_list.append(l1)
new_list.append(l2)
new_list.append(l3)
print(new_list)
# or
new_list = []
new_list+=[l1]
new_list+=[l2]
new_list+=[l3]

print(new_list)

Output:

[[1, 2], [5], [2, 7, 9]]
[[1, 2], [5], [2, 7, 9]]
[[1, 2], [5], [2, 7, 9]]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.