Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,870 questions

51,793 answers

573 users

How to create a nested list of tuples in Python

1 Answer

0 votes
# Create a nested list of tuples
data = [
    [(1, 2), (3, 4)],
    [(5, 6), (7, 8)],
    [(9, 10), (11, 12)]
]

# Print the entire structure
print("Nested list of tuples:", data)

# Accessing elements
print("First tuple in first sublist:", data[0][0])   # (1, 2)
print("Second tuple in second sublist:", data[1][1]) # (7, 8)

# Iterating through all tuples
print("\nAll tuples:")
for sublist in data:
    for tup in sublist:
        print(tup)



'''
run:

Nested list of tuples: [[(1, 2), (3, 4)], [(5, 6), (7, 8)], [(9, 10), (11, 12)]]
First tuple in first sublist: (1, 2)
Second tuple in second sublist: (7, 8)

All tuples:
(1, 2)
(3, 4)
(5, 6)
(7, 8)
(9, 10)
(11, 12)

'''

 



answered 6 hours ago by avibootz

Related questions

...