cosmologicon / pywat

Python wats
1.22k stars 99 forks source link

Indexing with floats - not really an index #29

Open WerthPADOH opened 8 years ago

WerthPADOH commented 8 years ago

I get how this one can seem weird to newcomers, but it's because dictionaries don't use indices.

>>> {1:4}[0]

Traceback (most recent call last):
  File "<pyshell#29>", line 1, in <module>
    {1:4}[0]
KeyError: 0

May be nit-picky, but I don't think indices and keys not being the same thing is a "wat."

This "wat" could be better shown as how two equivalent values are not equivalent in use:

>>> 0 == 0.0
True
>>> [4][0]
4
>>> [4][0.0]

Traceback (most recent call last):
  File "<pyshell#34>", line 1, in <module>
    [4][0.0]
TypeError: list indices must be integers, not float