Web Framework (97)

35 Name: #!/usr/bin/anonymous : 2008-02-05 18:22 ID:Heaven

> Your program will suddenly generate an error when faced with this data and your user will be unhappy.

Hmm. Let's see here...

>>> a = [u'ÞORN', 'PORN', 'YARN', 'ZEBRA', 'TOUHOU', 'TANK', 'PRALINE', 'PAGAN', 'THEME', 'TITMOUSE']
>>> a.sort()
>>> for i in a: print i

...
PAGAN
PORN
PRALINE
TANK
THEME
TITMOUSE
TOUHOU
YARN
ZEBRA
ÞORN

Oh look, no error.

And suppose you wanted to make an alphabetical index:

>>> for i in sorted(set(i[0] for i in a)): print i

...
P
T
Y
Z
Þ

Still no error, and it works fine. Now if you were just blindly manipulating strings, as you suggest, you would have a problem, because you'd be dumping the first byte of a multi-byte character. But you're right! Why would people need to see the entire letter anyway? They can just guess.

This thread has been closed. You cannot post in this thread any longer.