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

How many months it takes to learn Python good enough to get a job?
Ideally, it would take up to 2 months to learn Python good enough to get a job. However, it varies depending on the educational level of the student and how much hours the student is willing to put in per day.
Gene
0 0
5
Why does â??5/2 = 2â?? and not 2.5 in Python?
Due to dynamic Typing. use Numpy , and declare data type , you will get desired result
Srikanth
0 0
6
I want to develop website which uses rest-api and Inventory/stock functionality in Python-Django. From where should I start
Start with the design of the website. What is it's purpose. What should it contain and what it should not contain. Rent a website. I am assuming you know Python. Install Python and Django on your web server and implement your design
Sourav
0 0
9

which is best in Rpa and python

Python is much preferrable, I would suggest you to go for Python. As it is now a days used in Automations too.
K

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

Ask a Question

Related Lessons

Write your first Python program in 10 minutes
1. Download python from python official site search "python download" in google 2. Install in your machine 3. verify using : "python --version" command 4. Write first program using notepad create...

Python- Basic Concepts part 1
1. What is Python? Python is a high-level programming language, with applications in numerous areas, including web programming, scripting, scientific computing, and artificial intelligence. It is...

Using Lambda and Filter with Regular expressions.
1) Start the Python interpreter and import the re module: >>> import re 2)Define a tuple strings to filter with regular expressions: t=('python','pycon','perl','peril','step','stop','come','came','exercise','hello','storm','my.mail','year','yam') ...

Decorator Introduction
A decorator takes in a function, adds some functionality and returns it. Functions can be passed as arguments to another function like map, filter and reduce Function that take other functions as arguments...

Steps of Execution of a Python Program
When we compile a Python program, the python compiler converts the Python source code into another code called byte code. Byte code is a fixed set of instructions that represent different types of operations....

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