Hacker News new | past | comments | ask | show | jobs | submit login

I can stringify a list by saying map(str, numbers), because str() happens to be a function that I can map with. But I can’t capitalize a list in that way, because capitalize() is a method.

Yes, you can:

    >>> map(str.capitalize, ['alpha', 'beta', 'gamma'])
    ['Alpha', 'Beta', 'Gamma']



Or, if you have a list that might be of mixed types that happen to have capitalize methods:

    >>> import operator
    >>> map(operator.methodcaller("capitalize"), your_list)


Hot damn, I had no idea bout that module.....




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

Search: