python - How to separate a tuple with 2 parts into separate lists? -


so have tuple has 2 lists in it:

x = (['a', 's', 'd'], ['1', '2', '3']) 

how make 2 lists? right code looks like:

list1.append(x[1]) list1.append(x[2]) list1.append(x[3]) 

but can't add other 3 items separate list indexes 4, 5 , 6:

list2.append(x[4]) list2.append(x[5])      -results in error list2.append(x[6]) 

how can above make list2?

your tuple has 2 elements. reference directly:

list1 = x[0] list2 = x[1] 

or

list1, list2 = x 

this creates additional references 2 lists contained in x, not copies. if need new list objects same contents, create copies:

list1, list2 = x[0][:], x[1][:] 

see how clone or copy list?


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -