How to declare and print a dictionary with lists in Python

3 Answers

0 votes
my_dict = {
    "fruits": ["apple", "banana", "mango"],
    "numbers": [1, 2, 3, 4],
    "mixed": ["a", 10, True]
}

print(my_dict)


'''
run:

{'fruits': ['apple', 'banana', 'mango'], 'numbers': [1, 2, 3, 4], 'mixed': ['a', 10, True]}

'''

 



answered Mar 2 by avibootz
0 votes
my_dict = {
    "fruits": ["apple", "banana", "mango"],
    "numbers": [1, 2, 3, 4],
    "mixed": ["a", 10, True]
}

for key, value in my_dict.items():
    print(key, ":", value)


'''
run:

fruits : ['apple', 'banana', 'mango']
numbers : [1, 2, 3, 4]
mixed : ['a', 10, True]

'''

 



answered Mar 2 by avibootz
0 votes
my_dict = {
    "fruits": ["apple", "banana", "mango"],
    "numbers": [1, 2, 3, 4],
    "mixed": ["a", 10, True]
}

for key, value_list in my_dict.items():
    print(key + ":")
    for item in value_list:
        print("  -", item)



'''
run:

fruits:
  - apple
  - banana
  - mango
numbers:
  - 1
  - 2
  - 3
  - 4
mixed:
  - a
  - 10
  - True

'''

 



answered Mar 2 by avibootz
...