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

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

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

Disclosure: My content contains affiliate links.

43,569 questions

56,787 answers

573 users

How to flatten a nested list of tuples into a single 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)

# Flattening into a single list of tuples
flat_list = [tup for sublist in data for tup in sublist]
print("\nFlattened list:", flat_list)



'''
run:

Nested list of tuples: [[(1, 2), (3, 4)], [(5, 6), (7, 8)], [(9, 10), (11, 12)]]

Flattened list: [(1, 2), (3, 4), (5, 6), (7, 8), (9, 10), (11, 12)]

'''

 



answered Feb 9 by avibootz

Related questions

2 answers 318 views
...