Re: [Tutor] Dict operation question.

2005-07-08 Thread Javier Ruere
Kent Johnson wrote: > My understanding of the OP is that he wants an exception if there are items > in errdict. Also this solution will change self.somedict even in the error > case which may not be desirable. I understood what the OP said but think he expressed himself incorrectly or the alg

Re: [Tutor] Dict operation question.

2005-07-08 Thread David Driver
Really I was just wondering if this was a bad practice or if there was some way to get the same result. So if the list comprehension isn't a bad way to to it then I will stick with it. I am at the point where I have used python for simple stuff for a few years and I am attempting to get past a n

Re: [Tutor] Dict operation question.

2005-07-08 Thread Kent Johnson
Javier Ruere wrote: > I should also add the most simple and obvious implementation which is also > the fastest: > > > class Test: > def __init__(self, dict): > self.somedict = dict > > def updateit(self, **mydict): > errdict = {} > for k, v in mydict.iteritems():

Re: [Tutor] Dict operation question.

2005-07-08 Thread Kent Johnson
David Driver wrote: > I have a function > > def updateit(self,**mydict): > > which is intended to update a dictionary self.somedict. > > If there are keys in mydict that are not in self.somedict I want them > returned in a new dict. > > here is what i am doing now: > > errdict = dict([(a,b) f

Re: [Tutor] Dict operation question.

2005-07-07 Thread Javier Ruere
I should also add the most simple and obvious implementation which is also the fastest: class Test: def __init__(self, dict): self.somedict = dict def updateit(self, **mydict): errdict = {} for k, v in mydict.iteritems(): if k not in self.somedict:

Re: [Tutor] Dict operation question.

2005-07-07 Thread Javier Ruere
David Driver wrote: > I have a function > > def updateit(self,**mydict): > > which is intended to update a dictionary self.somedict. > > If there are keys in mydict that are not in self.somedict I want them > returned in a new dict. > > here is what i am doing now: > > errdict = dict([(a,b) f

[Tutor] Dict operation question.

2005-07-07 Thread David Driver
I have a function def updateit(self,**mydict): which is intended to update a dictionary self.somedict. If there are keys in mydict that are not in self.somedict I want them returned in a new dict. here is what i am doing now: errdict = dict([(a,b) for a,b in mydict.items() if not a in self.so