[Tutor] continuous running of a method

Hugo Arts hugo.yoshi at gmail.com
Wed Aug 25 09:12:46 CEST 2010

On Wed, Aug 25, 2010 at 12:56 AM, Greg Bair <gregbair at gmail.com> wrote:
> It's not that the value doesn't lie between the mentioned range.
> What I'm doing is randomly fetching an item from a list of dicts
> (multi-dimensional ones from a JSON response) and accessing a value from it,
> but not every item has the key I'm looking for (can't change that).  I
> suppose what I could do to not randomize every time is to iterate through
> the list and create a new list that only contains dicts that have that key,
> then get a random one from that.  I suppose that would be more efficient.
> Any thoughts?

this sounds like a good idea. Either the filter() function or a list
comprehension can filter out the dicts you want easily.

My guess is the list comprehension is somewhat faster, but I could be
wrong. And it doesn't sound like performance is a very big deal here
anyway, so take your pick.


More information about the Tutor mailing list