Subsetting a dictionary
Emile van Sebille
emile at fenx.com
Sun Mar 18 21:25:48 EST 2001
"Emile van Sebille" <emile at fenx.com> wrote in message
news:993qq3$4bajg$1 at ID-11957.news.dfncis.de...
> Rather than copying and then deleting from the copy, try building a new
> dictionary while adding only those that qualify.
>
> Something like: (untested)
>
> def subset(self, attr, value):
> # Copy semantics
> td = {}
without this line...Sorry :{
> td.data = self.data.copy()
> for ky, val in TrainingData.items():
> if ky[attr] == value:
> td[ky] = val
> return td
>
More information about the Python-list
mailing list