Linked Questions

23 votes
2 answers
113k views

X = [0,5,0,0,3,1,15,0,12] for value in range(0,len(X)): if X[value] <= 0: del X[value] print(X) print(X) I run the code but then i get an error saying that the list is out of ...
Andrews's user avatar
  • 239
10 votes
1 answer
10k views

I have a list composed with my defined items, each of which has a attribute .name t = [item1, item2] I want to remove item from the t list according to their attribute .name, like remove() or pop() ...
Liao Zhuodi's user avatar
  • 3,303
4 votes
2 answers
3k views

Given a list of numbers: L = [1, 2, 3, 4, 5] How do I delete an element, let's say 3, from the list while I iterate over it? I tried the following code but it didn't do it: for el in L: if el == ...
bodacydo's user avatar
  • 80.4k
1 vote
1 answer
3k views

I have the following structure on a JSON file: { "channels": [ "180873781382873088", "181268808055521280", "183484852287307777", "174886257636147201", "174521530573651968" ] } ...
Rodrigo Leite's user avatar
-3 votes
2 answers
2k views

I have list as follows: list = [u'windows 32bit', u'i7', u'5Mb', u'energenie_eu', u'nvidia_970'] I want to take out value '5Mb' out of it. So, suggest me how can i take out value '5Mb' seperated from ...
anamika email's user avatar
2 votes
2 answers
735 views

How to find and delete only one element in a list in Python? # Example:deleting only the first (1,2) in the list a = [(4, 5), (1, 2), (7, 5), (1, 2), (5, 2)] # result expected a = [(4, 5), (7, 5), (1,...
user3346439's user avatar
1 vote
3 answers
863 views

My code for this returns 'None'. In case my question is not clear if i take the list [1 , 3 , 4 , 5 ,5 , 7], I want the list [1 , 3 , 4 , 7] to be returned. My code is as follows: print("This program ...
J.Sharpe's user avatar
1 vote
4 answers
371 views

I have the following situation: data = {'key1' : 'value1', 'key2': [ {'subkey1': 'subvalue1', 'subkey2': 'subvalue2'}, {other ...
user avatar
0 votes
2 answers
109 views

I want to output difference two tuple and remove one element on tuple a = [(1,2),(2,3),(3,3)] if (1,2) in a: ## how to remove (1,2) on tuple i need output [(2,3),(3,3)] how to do it? Thanks,
Ramin Farajpour Cami's user avatar
-1 votes
1 answer
190 views

I'm trying to delete an object (in this case, and instance of a Fruit class) when it intersects with the head of my snake. The problem is that when it detects a fruit object, del doesn't appear to do ...
Python_plusSharp's user avatar
-2 votes
1 answer
72 views

For example I have a list that looks like this: l = [(1,2),(1,3),(4,1)] how can I remove item (1,3) without knowing the index of the item? I tried l.pop((1,3)) but I got this error message: ...
sam jack's user avatar
-1 votes
2 answers
69 views

I am trying to write a Suduoku game. Every time I use a number, I need to delete it from the list. I have already tried .pop[1], but it did nothing when the number was one. import random rownum1 = ...
Nathaniel Gamester's user avatar
0 votes
2 answers
50 views

For example: list = [1,7,2,8,9,2,7,9,2,8,2] How can I remove two of the "2" without removing the others?
m4ntorrassdafasdf's user avatar
0 votes
0 answers
29 views

Python beginner just wondering why is it you're not able to pop() an item from a list by using it's value within a list, instead having to know it's index? e.g. colours = ["blue", "...
Luke Gorman's user avatar
232 votes
5 answers
173k views

I notice that it is often suggested to use queues with multiple threads, instead of lists and .pop(). Is this because lists are not thread-safe, or for some other reason?
lemiant's user avatar
  • 4,455

15 30 50 per page