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

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
Which technology is better to learn Linux, java or python to get a good job please help me out in this?
If you have to absolutely choose only one of the three and are not from computer science stream, definitely Python and if you are from computer science stream, Java. If no restriction, choose both. and...
Sai
Are there coding standards or a style guide for Python programs?
The PEP 8 -- Style Guide for Python Code provides a fairly comprehensive list of Python naming conventions. Here are a few examples, but you should consult the PEP 8 style guide for more detailed information...
A
0 0
7

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

Ask a Question

Related Lessons

Python- Basic Concepts part 2
1. Other Numerical Operations a. Exponentiation Besides addition, subtraction, multiplication, and division, Python also supports exponentiation, which is the raising of one number to the power of...

Python Concurrent v/s Parallel Programming
Concurrent means, more than one task happening at a time in interleaved fashion, (ie.,)Task 'A' starts, and Task 'B' starts before task 'A' finish, after processing its(A and B) own purpose both the task...

Python SubProcess
Question: As a Network Administrator, one of my trainee wants to know the below: He has certain number of Machines(IP’s). On daily basic he wants to know how many IP’s are reachable and...

Decorator in Python - Simplified
By definition, a decorator is a function that takes another function andextends(/decorates) the behaviour of the latter function without explicitly modifying it.Let see how we can apply decorators for...

Why Python
Python can be used in any futuristics technology A= Analytics Data Science Artificial Intelligence(AI) Neural Network(NN) Natural Language Processing(NLP) Computer Vision(OpenCV) In Analytics...

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