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
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
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
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
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
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)
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,
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
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