I tried erlang-ish [1|2] in python and something came out...
clp at rebertia.com
Sun Sep 21 19:13:08 CEST 2008
On Sun, Sep 21, 2008 at 10:02 AM, process <circularfunc at gmail.com> wrote:
> In erlang you can cons like this: [1|2]. i tried this in python and it
> didnt raise an error but i dont know what the result do
In Python, like in C, the "|" operator on integers performs a bitwise-OR.
To "cons" nondestructively onto a list, do e.g. [head_value] + tail,
but note that this isn't very idiomatic.
CPython's lists are implemented internally as arrays, not linked
lists, hence why there's no "cons" operator in Python.
You may also be interested in list.append()
>>>> a = [2|2]
Follow the path of the Iguana...
More information about the Python-list