python challenge question (string manipulation)
Caleb Hattingh
caleb.hattingh at gmail.com
Thu Mar 30 01:20:25 EST 2006
Terry
That is very succint. Rewriting my shift function given earlier:
>>> import string
>>> alpha = string.ascii_lowercase
>>> print alpha
abcdefghijklmnopqrstuvwxyz
>>> def shift(lst, n):
return [lst[(i+len(lst)-n)%len(lst)] for i,item in enumerate(lst)]
>>> print shift(alpha,2)
['y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x']
Shorter and possibly as clear too; thanks!
Keep well
Caleb
More information about the Python-list
mailing list