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,885 questions

51,811 answers

573 users

How to to remove all tuples of length N from a list of tuples in Python

2 Answers

0 votes
tupleList = [(3, 7), (1, 2, 0), (9, 8, 3, 4), (9, 2), (3, 1, 0), (1, 4, 7, 8)] 

N = 2

tupleList = [tpl for tpl in tupleList if len(tpl) != N]

print(tupleList)



'''
run:

[(1, 2, 0), (9, 8, 3, 4), (3, 1, 0), (1, 4, 7, 8)]

'''

 



answered Nov 28, 2022 by avibootz
0 votes
tupleList = [(4, 9), (4, 0, 1), (5, 6), (1, 84, 83, 7), (4, 3), (6,)]

N = 2
 
result = list(filter(lambda x : len(x) != N, tupleList))

print(result)




'''
run:

[(4, 0, 1), (1, 84, 83, 7), (6,)]

'''

 



answered Dec 16, 2023 by avibootz

Related questions

...