w3resource

Python: Create multiple lists


Create Multiple Lists

Write a Python program to create multiple lists.

Python: 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:

Flowchart: Create multiple lists

For more Practice: Solve these Related Problems:

  • Write a Python program to create multiple lists dynamically based on user input.
  • Write a Python program to create multiple lists and store them in a dictionary with keys as list names.
  • Write a Python program to generate a list of lists where each list contains numbers in a specific range.
  • Write a Python program to create multiple lists from a single list based on a condition.

Go to:


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.

Python Code Editor:

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.