Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Winnow empty items #1

Open
kwinkunks opened this issue Dec 8, 2015 · 2 comments
Open

Winnow empty items #1

kwinkunks opened this issue Dec 8, 2015 · 2 comments

Comments

@kwinkunks
Copy link
Member

E.g. blank picks. True by default.

@EvanBianco
Copy link

For processing sets of picks on a given challenge, we can remove blank picks using a list comprehension like so. Perhaps this needs to be written as a function.

[pick for pick in picks if len(pick.picks) != 0]

I imagine there might be some other lightweight utility functions we'll need to define for cleaning and conditioning pick sets.

@kwinkunks
Copy link
Member Author

This is a good general pattern, but if you're just going to iterate over the result of this list comprehension, you can just do this:

filter(None, picks)

...because using None like this removes all falsy things. In this case, that's OK. It returns an iterator.

In your case you could also do [pick for pick in picks if pick] — again because the empty list is falsy. It reads pretty weird though.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants