Alex
Alex

Reputation: 21

Python nested list within a nested list without looping

I want to add a dictionary to a nested list within a nested list.

so;

['master_list 1', ['list 1', ['sub_list 1']], ['list 2'], ['list 3']]

would end up like;

['master_list_1', ['list_1', ['sub_list_1',{key_1:value_1}]], ['list_2'], ['list_3']]

I know the exact position within the lists that I want to add the dictionary, so can I add the dictionary without looping through other lists?

I have got as far as

master_list[0].append(list_1)

but I can't find out how to call the lower lists.

Upvotes: 1

Views: 405

Answers (1)

vivek
vivek

Reputation: 5219

master_list[1][1].append({key_1:value_1})

Upvotes: 3

Related Questions