Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

i didnt realize you could add the if statement in the comprehension where you did

    ['a' if i % 2 == 0 else 'b' for i in range(10)]
very cool!

I was only aware of code like

    ['a' for i in range(10) if i % 2 == 0]


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: