Linked Questions
878 questions linked to/from How to remove items from a list while iterating?
0 votes
1 answer
7k views
Sorting a list using for loop in python [duplicate]
I was trying to sort a list using for loops in python. I wrote the code like this. L=[1,2,3,6,7,9,4] NL=[] for i in L: NL.append(min(L)) L.remove(min(L)) print(NL) But here the output is [...
1 vote
5 answers
188 views
Deleting Occurences of Vowels in String [duplicate]
I'm trying to make a program that deleted all vowels from a string but for some reason it is not working. Here is my code in python 3 s = list(input()) vowels = ["A", "E", "I&...
0 votes
1 answer
3k views
List index out of range while removing elements from array [duplicate]
I know this is a basic question but here it's weird. I have no idea why this is giving the error. plz help me with this. Thanks in advance arr = [11,22,33,44,55,66,77] brr = [1,2,3,4,55] res_arr = ...
1 vote
2 answers
1k views
Delete nth row from a list of list - Python [duplicate]
My requirement is to delete the row having any element with text "Podcast" . audio is list of lists of xml elements for i in range(len(audio)): for j in range(len(audio[i])): ...
0 votes
2 answers
1k views
Remove not int elements in list [duplicate]
Hi I have this task in python and I should remove all not int elements, the result of the code down below is [2, 3, 1, [1, 2, 3]] and I have no idea why in the result the list is not moved away. Only ...
0 votes
4 answers
1k views
Getting index out of range error when trying to remove a list element [duplicate]
I have a list such as this: l = ['(7 - 3)', '7 - 6', '(a + 13)'] I want to remove any expression that does NOT contain the letter "a" therefore the only expression that would be left is ['(a+13)']. ...
2 votes
3 answers
1k views
Python: Search List of Tuples, Remove Entire Index [duplicate]
Possible Duplicate: Remove items from a list while iterating in Python I have a fairly embedded list: specifically, it is a list of lists of tuples. To simplify things, the entire list is a list ...
0 votes
5 answers
307 views
Python problem with list - removing duplicates [duplicate]
I am quite new to python and trying to remove some duplicates from a list following below code. I am getting a list index out of range error which doesn't make sense to me. Thankful for any advice. ...
2 votes
3 answers
2k views
How to iterate through the first elements of a list of tuples? [duplicate]
I have a list of tuples, all contain 1 phrase and 1 number. Example: [('light blue', 3), ('light green', 4), ('blue shade', 2), ('deep red', 3), ('dark red')] I would like to remove tuples from the ...
0 votes
1 answer
2k views
Python: Remove entry in a nested list [duplicate]
I have a nested list that I would like to delete rows after it has finished with them. i tried using enumerating to pass in the index of the row to delete. nlist = [['Chris', 'Davids', 21], ['Rob', '...
0 votes
2 answers
1k views
How to use built-in function pop in python? [duplicate]
I am confused about a really simple problem with list built-in function, pop. The code is simple as it can be. L=[1,2] for i in L: print i L.pop(0) and it gives 1 I tried it with a longer ...
0 votes
2 answers
2k views
Removing coordinates from list on python [duplicate]
I have created a list full of "coordinates" in Python: L1 = [(1,2), (5,6), (-1,-2), (1,-2), etc..]. If I wanted to remove all items in the list which contained negative numbers, how would I do this? ...
0 votes
1 answer
591 views
Removing elements in Python list [duplicate]
My code: ipList = ["192.168.0.1", "sg1234asd", "1.1.1.1", "test.test.test.test"] blackList = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "...
1 vote
2 answers
1k views
Removing items from a list in python following validity check [duplicate]
Background: I am writing a little script which requires, as one of it's arguments, an email address list in a file. The script will them go on to use the email address over a telnet connection to an ...
0 votes
3 answers
476 views
How to delete record from a nested list in a loop? [duplicate]
I have nested list like that [a,1],[b,2],[c,3] My code: for i in list: if i[0] == 'b': del i And thats just not working. Code do not crash, but it does not delete neither. I was trying ...