Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inline iteration and conditioning #6388

Closed
saifuddin778 opened this issue Apr 3, 2014 · 4 comments
Closed

inline iteration and conditioning #6388

saifuddin778 opened this issue Apr 3, 2014 · 4 comments

Comments

@saifuddin778
Copy link

I guess there is no guidelines present so for inline looping with conditioning.. like a common way can be:

t = [for a in something if a > some_value else 0]

Or is there any standard guideline around that I am not able to find? Thanks :-)

@JeffBezanson
Copy link
Sponsor Member

Dup of #550

@ivarne
Copy link
Sponsor Member

ivarne commented Apr 3, 2014

#550 is about ignoring elements in the list comprehension. If you don't want to ignore some values in the resulting array, you can use the tertiary cond ? a : b operator.

 t = [a > some_value ?  a : 0 for a in something]

@JeffBezanson
Copy link
Sponsor Member

Ah, excellent point, I should have read more carefully.

@saifuddin778
Copy link
Author

thanks guys. great help.

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

No branches or pull requests

3 participants