del Questions

20

Solved

How do I delete an item from a dictionary in Python? Without modifying the original dictionary, how do I obtain another dict with the item removed? See also How can I remove a key from a Python di...
Ovoid asked 30/4, 2011 at 21:20

6

Given a model, e.g. from gensim.models.word2vec import Word2Vec documents = ["Human machine interface for lab abc computer applications", "A survey of user opinion of computer system response ti...
Visser asked 23/2, 2018 at 5:26

22

Solved

I can't really think of any reason why Python needs the del keyword (and most languages seem to not have a similar keyword). For instance, rather than deleting a variable, one could just assign Non...
Alleneallentown asked 27/5, 2011 at 1:37

8

Solved

Can someone explain why the following code behaves the way it does: import types class Dummy(): def __init__(self, name): self.name = name def __del__(self): print "delete",self.name d1 = Du...
Zoophilia asked 24/5, 2011 at 0:24

1

Solved

I have a bunch of instances, each having a unique tempfile for its use (save data from memory to disk and retrieve them later). I want to be sure that at the end of the day, all these files are rem...
Lucrative asked 7/6, 2021 at 8:27

4

Solved

Calling del on a variable in Python. Does this free the allocated memory immediately or still waiting for garbage collector to collect? Like in java, explicitly calling del has no effect on when th...
Ramsgate asked 19/2, 2013 at 23:42

2

Solved

I have a python class object and I want to assign the value of one class variable class Groupclass(Workerclass): """worker class""" count = 0 def __init__(self): """initialize time""" Groupc...
Nomenclature asked 5/8, 2013 at 12:56

1

Solved

I'd like to remove temp build files during or after my laravel-mix build. Here's some code that I have currently, but del isn't working: const mix = require('laravel-mix'); const del = require('de...
Morton asked 14/12, 2018 at 11:41

4

I have to load this massive object A (that can weight almsot 10go) that I need to pass to a function, that extracts from it a parameter B to further exert some heavy computations on it. A = load(f...
Mariquilla asked 4/1, 2017 at 10:9

9

How do I delete a "column" from a list of lists? Given: L = [ ["a","b","C","d"], [ 1, 2, 3, 4 ], ["w","x","y","z"] ] I would like to delete "column" 2 to get: L = [ ["a","b","d"], [ 1, 2,...
Brindled asked 6/11, 2012 at 4:36

4

Solved

I create many object then I store in a list. But I want to delete them after some time because I create news one and don't want my memory goes high (in my case, it jumps to 20 gigs of ram if I don'...
Maurilla asked 22/1, 2013 at 18:13

4

Solved

I have a pandas df that I want to manipulate so it's ordered. So for the df below, I'd like ['I'] to be ordered. So values would read 10-50. I have 2 options to do this; 1) Try to delete values in...
Christchurch asked 1/6, 2018 at 2:0

3

Solved

del seems to have some memory which puzzles me. See the following: In [1]: import math In [2]: math.cos(0) Out[2]: 1.0 In [3]: del math.cos In [4]: math.cos(0) ---------------------------------...
Sanjay asked 15/2, 2018 at 14:20

1

Solved

I have a loop in a batch file to delete all but one file in a directory (Windows 7). But it hangs up because it still sends the commands to the screen, even though I'd thought I'd suppressed it. He...
Cementum asked 14/8, 2017 at 16:7

5

Solved

Normally, I get the key set then use a look to delete each key/value pair. Is it possible to just delete all keys via pattern? ie: Del sample_pattern:*
Cotsen asked 23/1, 2014 at 19:23

6

Solved

I have a list of strings ['foo1', 'foo2', ...] that represent variables that I want to delete from self if they are part of self. What is a Pythonic and compact way to do this? My first attempt is...
Alanson asked 17/2, 2017 at 17:6

4

I m trying to do a some activity on class obj destruction. How do I achieve file open in __del__ function? (I m using Python 3.4) class iam(object): def __init__(self): print("I m born&quot...
Suksukarno asked 24/10, 2014 at 8:22

2

Solved

In my python program, I use pandas to read a csv file and store in memory: data = pandas.read_csv('data.csv') Before running the above command I check the free memory with free -m and the output...
Gollin asked 1/2, 2016 at 1:17

3

Solved

I'm working through a pluralsight course on gulp. John Papa is demonstrating how to inject a function that deletes existing css files, into the routine that compiles the new ones. The callback on ...
Scherzo asked 24/9, 2015 at 21:5

8

Solved

This may be silly, but it's been nagging the back of my brain for a while. Python gives us two built-in ways to delete attributes from objects, the del command word and the delattr built-in funct...
Moniliform asked 13/7, 2009 at 17:33

4

Solved

Why does the following code change both variables: >>> a = [] >>> b = a >>> a.append(9) >>> a [9] >>> b [9] >>> But the del statement does ...
Treat asked 30/4, 2014 at 0:12

4

Solved

I have a small piece of code and a very big doubt. s=['a','+','b'] s1=s print s1 del s1[1] print s1 print s The output is value of s1 ['a', '+', 'b'] value of s1 ['a', 'b'] value of s ['...
Alston asked 24/2, 2014 at 8:58

2

Solved

I am trying to figure out the best way to remove something, preferably without having to write in a lot of code. In my project I am simulating chemical compounds - I have Element instances bonded ...
Ternopol asked 13/2, 2014 at 22:8

1

Solved

I have read the python docs for list and how the del operators works, but I need explanation for the following behavior In this case, c and l points to the same object(list), so doing changes on o...
Decoration asked 30/12, 2013 at 20:37

3

Solved

Is there a one line way of doing the below? myDict = {} if 'key' in myDic: del myDic['key'] thanks
Criticaster asked 21/2, 2012 at 11:59

© 2022 - 2024 — McMap. All rights reserved.