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

SVM is applicable only for numeric data or can also be for textual data?
Any learning algorithm for that matter does not work Directly on text. It needs to be converted to a structured matrix before applying algorithms.The methods involve - 1. Extensive cleaning of the data...
Harsha
Which is better, PHP or Python? Why?
Python . Simple syntax,More readable,General purpose programming language
Kartheek
0 0
5

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

Ask a Question

Related Lessons

Writing Simple Programs in Python
Writing a program, especially for a beginner, is a challenging and daunting task! He/She knows the language but is not able to start. To make things simple, it is advisable to follow a process that is...

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...

Assignment operators
Operation Syntax Comment Assignment = Control flow right to left Add AND += Incremental Subtract AND -= Decremental Multiply AND *= Multiplicative increment Division...

Code: Gantt Chart: Horizontal bar using matplotlib for tasks with Start Time and End Time
import pandas as pd from datetime import datetimeimport matplotlib.dates as datesimport matplotlib.pyplot as plt def gantt_chart(df_phase): # Now convert them to matplotlib's internal format... ...
R

Rishi B.

0 0
0

Python - Solving Ordinary Differential Equations - Predator Prey Model aka Lotka Volterra Equations
This is an assignment in Python, I contributed to a numerical Python MOOC from George Washington University. The link to this assignment on github is here. The Lotka–Volterra equations, also...
S

Sri Vallabha Deevi

0 0
1

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