UrbanPro

Learn Python Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

How to remove matching elements from two nested lists while iterating

Asked by Last Modified  

25 Answers

Learn Python

Follow 0
Answer

Please enter your answer

Trainer

for i in list_1: for j in list_2: if i==j: list_1.remove(i) list_2.remove(j)
Comments

IT Teacher

a= b= for i in a: if a in b: a.remove(i) b.remove(i)
Comments

for set in dataSet: for item in set: if item=="311472": dataSet.remove(item)
Comments

Train the students to shine in IT world.

Try with this: 1. Instead of deleting an element from the loop I would suggest you to try with the While loop. 2. Once when the iteration completed then delete the item lists which you would like to delete from the item list.
Comments

IT Teacher

Here is the code to do a= b= for i in a: if i in b: a.remove(i) b.remove(i) print("a:%s,b:%s",%(a,b))
Comments

Trainer

You can use list iterators, and can delete the elements while traversing the list.
Comments

l=,] flag = 0 for x in l: if (flag == 0): list1=x flag = 1 else: list2=x if : print("Number was found") list1.remove(item) list2.remove(item) else: print("Number not in list")
Comments

IT Professional Trainer with 15 years of experience in IT Industry

You could always iterate over a copy of the list, leaving you free to modify the original: for item in list(somelist): ... somelist.remove(item)
Comments

Expert Php Developer and Php Programing Teacher

in nested loop check if value is equal to parent while loop
Comments

Trainer

First unpack the nested list(L) into two separate lists (L1, L2). Then create a new list LC which contains common elements from L1 and L2. Iterate through LC, for each element 'elem', use L.remove(elem) and L.remove(elem)... Then display L. You will not see the matching elements in the two nested lis...
read more
First unpack the nested list(L) into two separate lists (L1, L2). Then create a new list LC which contains common elements from L1 and L2. Iterate through LC, for each element 'elem', use L[0].remove(elem) and L[1].remove(elem)... Then display L. You will not see the matching elements in the two nested lists.... read less
Comments

View 23 more Answers

Related Questions

Between Java and Python, which one is better to learn first and why?
Both the development programs come with their strong suits. While Java allows you to enjoy the cross-platform support, Python helps you execute on at least ten different operating systems. It would help...
Priyanka
0 0
5
While teaching IT Student (MCA / BCA / BTech), I found most of the students are not having good programming skills but they are still running behind to learn .NET / PHP / PYTHON / ANDROID / JAVA. Why is it so? What we should do better to improve a sound programming skills among most of IT Students?
on college days they r learning c,c++ and following faculties are also giving a road map of "programming means" thease languages only , even these are the languages are familier , where you justify them...
Amit Kumar

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

DBMS - SQL - Any/All
All - Operator SELECT empno, sal FROM emp WHERE sal > ALL (1999, 2999, 3999); Output of Above query is same as below query SELECT empno, sal FROM emp WHERE sal > 1999 AND sal > 2999...

Radhe Shyam

0 0
0

Be A Python Dev
Currently, in the programming world, Python is one of the languages with a high rising demand profile. And this article will explain why that isn’t slowing down in the foreseeable future.Python...


Be prepared to get trained--init
Before starting the training,students must be mentally prepared for acceptance of new knowledge. Students must attend training with open minded forgetting the position they are working.This will help...
S

Smartnub Softsolutions

0 0
0

Python Dictionary
Python dictionary is an unordered collection of items. While other compound datatypes have only value as an element, a dictionary has a key: value pair. Dictionaries are optimized to retrieve values when...

Recommended Articles

Python is one of the most popular programming languages in the world. It is general-purpose, object oriented, high-level programming language used in a number of programming fields. Python is a great programming language to learn as it will introduce you to the world of programming. If you are from the technical background...

Read full article >

Almost all of us, inside the pocket, bag or on the table have a mobile phone, out of which 90% of us have a smartphone. The technology is advancing rapidly. When it comes to mobile phones, people today want much more than just making phone calls and playing games on the go. People now want instant access to all their business...

Read full article >

Software Development has been one of the most popular career trends since years. The reason behind this is the fact that software are being used almost everywhere today.  In all of our lives, from the morning’s alarm clock to the coffee maker, car, mobile phone, computer, ATM and in almost everything we use in our daily...

Read full article >

Hadoop is a framework which has been developed for organizing and analysing big chunks of data for a business. Suppose you have a file larger than your system’s storage capacity and you can’t store it. Hadoop helps in storing bigger files than what could be stored on one particular server. You can therefore store very,...

Read full article >

Looking for Python Training classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Python Training Classes?

The best tutors for Python Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Python Training with the Best Tutors

The best Tutors for Python Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more