Re: [Tutor] deleting elements of a dictionary (Mats Wichmann)

2017-05-24 Thread Sergio Rojas
Having now done a quick check, mydict.pop() is no better for this case. Here's a simplistic sample that does work: d = { 100:3, 200:4, 111:5, 222:5, 333:5, 500:6, } print "original: ", d new = {key:value for (key,value) in d.iteritems() if value != 5} print "new: ", new

Re: [Tutor] deleting elements of a dictionary

2017-05-20 Thread Mats Wichmann
On 05/19/2017 02:54 PM, Mats Wichmann wrote: > On 05/19/2017 11:17 AM, Alan Gauld via Tutor wrote: >> On 19/05/17 15:23, Michael C wrote: >>> list(read_dictionary) converts the dictionary into a list right? How can >>> you save the list as a dictionary? >> >> Nope, list() produces a new list

Re: [Tutor] deleting elements of a dictionary

2017-05-19 Thread Mats Wichmann
On 05/19/2017 11:17 AM, Alan Gauld via Tutor wrote: > On 19/05/17 15:23, Michael C wrote: >> list(read_dictionary) converts the dictionary into a list right? How can >> you save the list as a dictionary? > > Nope, list() produces a new list object containing the > keys of the dictionary. In the

Re: [Tutor] deleting elements of a dictionary

2017-05-19 Thread Alan Gauld via Tutor
On 19/05/17 15:23, Michael C wrote: > list(read_dictionary) converts the dictionary into a list right? How can > you save the list as a dictionary? Nope, list() produces a new list object containing the keys of the dictionary. In the old day(of python 2) you used to get the same effect using for

Re: [Tutor] deleting elements of a dictionary

2017-05-19 Thread Michael C
list(read_dictionary) converts the dictionary into a list right? How can you save the list as a dictionary? Thanks! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] deleting elements of a dictionary

2017-05-19 Thread Peter Otten
Michael C wrote: > for n in list(read_dictionary): >> print(read_dictionary[n]) >> if read_dictionary[n] == '5': >> del read_dictionary[n] > > After doing this how do I save it back to the dictionary? > then i ll do this > numpy.save('loc_string_dictionary.npy', dictionary)

Re: [Tutor] deleting elements of a dictionary

2017-05-19 Thread Michael C
for n in list(read_dictionary): > print(read_dictionary[n]) > if read_dictionary[n] == '5': > del read_dictionary[n] After doing this how do I save it back to the dictionary? then i ll do this numpy.save('loc_string_dictionary.npy', dictionary) On Thu, May 18, 2017 at 3:05 PM,

Re: [Tutor] deleting elements of a dictionary

2017-05-18 Thread Peter Otten
Michael C wrote: > I am trying to remove incorrect entries of my dictionary. > I have multiple keys for the same value, > > ex, > [111]:[5] > [222]:[5] > [333]:[5} > > and I have found out that some key:value pairs are incorrect, and the best > thing to do > is to delete all entries who value

[Tutor] deleting elements of a dictionary

2017-05-18 Thread Michael C
I am trying to remove incorrect entries of my dictionary. I have multiple keys for the same value, ex, [111]:[5] [222]:[5] [333]:[5} and I have found out that some key:value pairs are incorrect, and the best thing to do is to delete all entries who value is 5. So this is what I am doing: import