POV-Ray : Newsgroups : povray.off-topic : Innovative open source? : Re: Innovative open source? Server Time
9 Oct 2024 13:15:41 EDT (-0400)
  Re: Innovative open source?  
From: nemesis
Date: 4 Apr 2009 12:55:00
Message: <web.49d790d5aca2c31c1ec805060@news.povray.org>
Mueen Nawaz <m.n### [at] ieeeorg> wrote:
> nemesis wrote:
> > It can take arbitrary objects as keys and has a wealth of good methods to choose
> > from.  Perhaps it's time for some friday night troll? ;)
>
>  Unless they made changes, that's not correct. It can only take strings,
> numbers, and immutable types as keys (so no lists, but yes tuples).

Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> ls = dir()
>>> ls
['__builtins__', '__doc__', '__name__']
>>> d = {}
>>> d[ls]=1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: list objects are unhashable
>>> str
<type 'str'>
>>> d[str]="string class"
>>> d
{<type 'str'>: 'string class'}
>>> d[lambda x:x+1]="function object as key"
>>> d
{<type 'str'>: 'string class', <function <lambda> at 0x838aa3c>: 'function
object as key'}

True, lists can't be used as key.  But classes, objects and even functions can.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.