[Tutor] 'Name Genereator' Question

Tim Peters tutor@python.org
Wed, 3 Jan 2001 23:58:24 -0500

[Daniel Yoo]
> Wait!  Yes, on a second thought, you _can_ do a map() on a
> string --- but you need to first convert it to a list.  So you could
> write a character-replacing function (let's call it replaceChar()),
> and then do this:

Actually, a string is one of Python's sequence types (and, for example,
lists and tuples are also sequences), and map works on any sequence:

>>> map(ord, "ABC")
[65, 66, 67]
>>> map(chr, _)
['A', 'B', 'C']


> ###
> def replaceString(str):
>     result = map(replaceChar, list(str))
                                ^^^^^   ^

you really don't need the list() function there.  But it's OK to use it if
you want to <wink>.