473,385 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

I tried erlang-ish [1|2] in python and something came out...

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
>>[1|2]
[3]
>>[2|2]
[2]
>>a = [2|2]
a
[2]
>>[2|3]
[3]
>>[2|1]
[3]
>>>
Sep 21 '08 #1
2 1093
process 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 | is the logical bitwise-OR operator. Look at the binary
representation of the numbers to understand it.

Gary Herron
>
>>>[1|2]
[3]
>>>[2|2]
[2]
>>>a = [2|2]
a
[2]
>>>[2|3]
[3]
>>>[2|1]
[3]

--
http://mail.python.org/mailman/listinfo/python-list
Sep 21 '08 #2
On Sun, Sep 21, 2008 at 10:02 AM, process <ci**********@gmail.comwrote:
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()

Regards,
Chris
>
>>>[1|2]
[3]
>>>[2|2]
[2]
>>>a = [2|2]
a
[2]
>>>[2|3]
[3]
>>>[2|1]
[3]
>>>>
--
http://mail.python.org/mailman/listinfo/python-list
--
Follow the path of the Iguana...
http://rebertia.com
Sep 21 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rob Ristroph | last post by:
Has anyone tried out the PHP 5 beta ? If so do you have any comments ? I tried to install it a week ago on RedHat 9, but could not get the build system to make the libphp5.so module. --Rob
4
by: Sidharta | last post by:
Hi all, how come this doesn't work????? # convert to unix new lines $text = preg_replace("/\r\n/", "\n", $text); # remove extra new lines $text = preg_replace("/\n+/", "\n", $text); is...
4
by: LP | last post by:
Hi, My webservice is currently deployed on WIndows 2000 server and runs pretty fine. I am trying to run my webservice on a Windows 2003 server. My webservice tries to write to a eventlog. The...
31
by: Jim Hubbard | last post by:
I am downloading the REALbasic 5.5 demo and was just wondering if anyone else had tried it. I am tired of Microsoft constantly changing things and breaking backward compatibility ON PURPOSE. ...
16
by: LP | last post by:
Hello, I am trying to use .NET with Excel. I installed Office 2003 and selected ..NET programming suport option, so it installed all those PIA, as MS sugests. But I can not find a way to destroy...
3
by: nsh | last post by:
mailing.database.mysql, comp.lang.php subject: does "LOAD DATA" EVER work?!? I've tried EVERYTHING! version info: my isp is running my web page on a linux box with php ver. 4.4.1 according to...
7
by: maya | last post by:
hi, I got this unusual design (well, not so unusual anymore, I guess..) for an input text field for a search form in top of page.. http://www.mayacove.com/design/search/search.html I can't...
6
by: sweatha | last post by:
Hi I have to select count(Date) from Appointment table having count<5. If count(Date)<5 then I should insert the data from my page. For that I have given the coding as protected void...
11
by: mjahabarsadiq | last post by:
Hi I have created a web application. I am using ant to build the war and deploy in tomcat. The war file is deployed under "TOMCATE_HOME/work/standalone/localhost/onlineres.war". I have my...
6
by: belias | last post by:
So...here we go. I'm having an issue with one computer on a network not being able to ping other computers by name. I've spent the last day searching similar issues and I've tried all the steps...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.