cosmologicon / pywat

Python wats

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Indexing with floats - not really an index

WerthPADOH opened this issue · comments

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