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
Post a Comment