Python: Display each element vertically of a given list, list of lists
Display List Vertically
Write a Python program to display vertically each element of a given list, list of lists.
Visual Presentation:


Sample Solution:
Python Code:
# Create a list 'text' containing string elements.
text = ["a", "b", "c", "d", "e", "f"]
# Print a message indicating the original list.
print("Original list:")
print(text)
# Print a message indicating the intention to display each element of the list vertically.
print("\nDisplay each element vertically of the said list:")
# Iterate through the elements in the list 'text' and print each element on a separate line.
for i in text:
print(i)
# Create a list of lists 'nums' containing sublists of integers.
nums = [[1, 2, 5], [4, 5, 8], [7, 3, 6]]
# Print a message indicating the original list of lists.
print("Original list:")
print(nums)
# Print a message indicating the intention to display each element of the list of lists vertically.
print("\nDisplay each element vertically of the said list of lists:")
# Use 'zip' and tuple unpacking to iterate through and print the elements in sublists vertically.
for a, b, c in zip(*nums):
print(a, b, c)
Sample Output:
Original list: ['a', 'b', 'c', 'd', 'e', 'f'] Display each element vertically of the said list: a b c d e f Original list: [[1, 2, 5], [4, 5, 8], [7, 3, 6]] Display each element vertically of the said list of lists: 1 4 7 2 5 3 5 8 6
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program to display each character of a list of strings vertically with specified column spacing.
- Write a Python program to display a 2D list vertically, aligning the output columns based on the maximum element width.
- Write a Python program to print the elements of a list of tuples vertically, with each tuple’s items printed on separate lines.
- Write a Python program to display a list of lists vertically, padding shorter sublists with spaces to align the columns.
Python Code Editor:
Previous: Write a Python program to convert a given list of strings into list of lists.
Next: Write a Python program to convert a given list of strings and characters to a single list of characters.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics