Python: Create multiple lists
Python List: Exercise - 41 with Solution
Create Multiple Lists
Write a Python program to create multiple lists.
Sample Solution:
Python Code:
# Create an empty dictionary named 'obj'
obj = {}
# Iterate through the range of numbers from 1 to 20
for i in range(1, 21):
# Create an empty list as the value and associate it with the string representation of the number 'i' as the key in the dictionary 'obj'
obj[str(i)] = []
# Print the resulting dictionary 'obj'
print(obj)
Sample Output:
{'1': [], '8': [], '14': [], '5': [], '17': [], '9': [], '2': [], '7': [], '16': [], '19': [], '4': [], '18': [], '13': [], '3': [], '15': [], '11': [], '20': [], '6': [], '12': [], '10': []}
Flowchart:
Python Code Editor:
Previous: Write a Python program to split a list based on first character of word.
Next: Write a Python program to find missing and additional values in two lists.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/python-exercises/list/python-data-type-list-exercise-41.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics