python - Difference between [y for y in x.split('_')] and x.split('_') -


i've found this question , 1 thing in original code bugs me:

>>> x="alpha_beta_gamma" >>> words = [y y in x.split('_')] 

what's point of doing this: [y y in x.split('_')]? split returns list , items aren't manipulated in list comprehension. missing something?

you're correct; there's no point in doing that. however, it's seen in combination kind of filter or other structure, such [y y in x.split('_') if y.isalpha()].


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -