[Python-ideas] str.startswith taking any iterator instead of just tuple

Chris Angelico rosuav at gmail.com
Mon Jan 6 01:27:08 CET 2014


On Mon, Jan 6, 2014 at 4:48 AM, Andrew Barnert <abarnert at yahoo.com> wrote:
> And if you want to extend that set of builtins with similar functions, how else would you do it but with a "for ch in s" loop? (Well, you could "for ch in list(s)", but that's still treating strings as iterables.)

You could simply "for ch in s.split('')". A number of languages define
that to mean fracturing a string into one-character strings. Python
currently raises ValueError, so it won't break existing code.

But yes, it's easier to be able to iterate over a string.

ChrisA


More information about the Python-ideas mailing list