[Tutor] Debugging a sort error.
Stephen Nelson-Smith
sanelson at gmail.com
Sun Jan 13 09:15:08 EST 2019
Hi,
On Sun, Jan 13, 2019 at 8:34 AM <mhysnm1964 at gmail.com> wrote:
> description.sort()
> TypeError: unorderable types: float() < str()
So, fairly obviously, we can't test whether a float is less than a
string. Any more than we can tell if a grapefruit is faster than a
cheetah. So there must be items in description that are strings and
floats.
With 2000 lines, you're going to struggle to eyeball this, so try
something like this:
In [69]: irrational_numbers = [3.14159265, 1.606695, "pi", "Pythagoras
Constant"]
In [70]: from collections import Counter
In [71]: dict(Counter([type(e) for e in irrational_numbers]))
Out[71]: {float: 2, str: 2}
If with your data, this shows only strings, I'll eat my hat.
S.
More information about the Tutor
mailing list