How to insert into python nested list -


i want insert item list inside list. i'm wondering if can show me.

list5 = [[], [(1,2,3,4), 2, 5]] print("1. list5", list5) list5.insert(0, (2,5,6,8)) print("2. list5", list5)  output: 1. list5 [[], [(1, 2, 3, 4), 2, 5]] 2. list5 [(2, 5, 6, 8), [], [(1, 2, 3, 4), 2, 5]] 

i want:

2. list5 [[(2, 5, 6, 8)], [(1, 2, 3, 4), 2, 5]] 

a dictionary unfortunately won't work.

the problem trying insert first element of list, list5 incorrect. have access first element of list , insert list. can done using following code

>>> list5 = [[], [(1,2,3,4), 2, 5]] >>> print("1. list5", list5) 1. list5 [[], [(1, 2, 3, 4), 2, 5]] >>> list5[0].insert(0, (2,5,6,8)) >>> print("2. list5", list5) 2. list5 [[(2, 5, 6, 8)], [(1, 2, 3, 4), 2, 5]] 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -