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

Sometimes it is, sometimes it's not. If you allow me to generalize this to list comprehensions vs. standard functional techniques, sometimes the list comprehension is cleaner. Take the list comprehension

  [f for f in os.listdir('.') if f.endswith('.csv') and not f.endswith('_avg.csv')]
The lambda alternative (which would make a great blog name) is

  filter(lambda f: f.endswith('.csv') and not f.endswith('_avg.csv'), os.listdir('.'))
I find the list comprehension cleaner because it introduces less noise.


Agreed.

> The lambda alternative (which would make a great blog name)

I'm stealing that.


Dammit!




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: