2

How to add values ​​to each list?

before :

[['2010', '10', '24', '20', '32', '18', '5'], ['2020', '16', '22', '23', '30', '16', '9'], ['2030', '28', '19', '29', '30', '12', '13']]

result : [list] value add ''

[['2010', '10', '24', '20', '32', '18', '5', ''], ['2020', '16', '22', '23', '30', '16', '9', ''], ['2030', '28', '19', '29', '30', '12', '13', '']]
0

2 Answers 2

3

Use for loop,

nested_list = [['2010', '10', '24', '20', '32', '18', '5'], ['2020', '16', '22', '23', '30', '16', '9'], ['2030', '28', '19', '29', '30', '12', '13']]

for a_list in nested_list:
    a_list.append('')
Sign up to request clarification or add additional context in comments.

Comments

2

You could also do following:

my_list = [['2010', '10', '24', '20', '32', '18', '5'], 
           ['2020', '16', '22', '23', '30', '16', '9'],
           ['2030', '28', '19', '29', '30', '12', '13']]

my_list = [inner_list + [''] for inner_list in my_list]
my_list

Output:

[['2010', '10', '24', '20', '32', '18', '5', ''],
 ['2020', '16', '22', '23', '30', '16', '9', ''],
 ['2030', '28', '19', '29', '30', '12', '13', '']]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.