Reputation: 67
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', '']]
Upvotes: 2
Views: 88
Reputation: 18208
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', '']]
Upvotes: 2
Reputation: 3428
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('')
Upvotes: 3