How to append a dictionary to a list in Python

1 Answer

0 votes
dict = {'python': 5, 'php': 3, 'java': 9, 'c++': 1}

lst = [1, 2, 'a']

dict_copy = dict.copy() 

lst.append(dict_copy)

print(lst)   


    
    
'''
run:
    
[1, 2, 'a', {'python': 5, 'php': 3, 'java': 9, 'c++': 1}]
    
'''

 



answered Jun 27, 2022 by avibootz
edited Jun 27, 2022 by avibootz
...