Created
September 3, 2013 07:02
-
-
Save nigelbabu/6420526 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# with lambda | |
pkg_dict['resources'] = filter(lambda x: x.get('id') != id, pkg_dict.get('resources', [])) | |
#without lambda | |
for res in pkg_dict.get('resources', []): | |
if res.get('id') == id: | |
pkg_dict['resources'].remove(id) |
Like the filter option better ;) - since id is the key can't you convert this to a dict and then access by id?
Note only works if you don't have multiple resources per id (don't know your data)
pd=dict((x.get('id'),x) for x in pkg_dict.get('resources',[]))
return pd.get(id)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can't you do something like