I was looking at a way to implement Ruby's upto method in python. I came
up with the code below... three years ago, I would never have thought of
list comprehension, today it seems second nature. This may be totally
un-Pythonic, but I thought it was kind of clever. Man, for some reason,
I feel like being rude and lofty acting :)
low_odds = [1,3,5,7,9]
# make a list containing 10 - 98 evens only
big_evens = big_evens = [x for x in list(xrange(99)) if x % 2 == 0 and
x >8]
low_evens = [2,4,6,8]
# make a list containing 11 - 99 odds only
big_odds = [x for x in list(xrange(100)) if x % 2 != 0 and x >9]
y = 8
if y in low_evens:
ok_numbers = low_odds + big_evens + [x for x in low_evens if x <= y] 3 1230
On Oct 10, 2007, at 2:51 PM, brad wrote:
I was looking at a way to implement Ruby's upto method in python. I
came
up with the code below... three years ago, I would never have
thought of
list comprehension, today it seems second nature. This may be totally
un-Pythonic, but I thought it was kind of clever. Man, for some
reason,
I feel like being rude and lofty acting :)
low_odds = [1,3,5,7,9]
# make a list containing 10 - 98 evens only
big_evens = big_evens = [x for x in list(xrange(99)) if x % 2 ==0
and
x >8]
big_evens = range(10, 100, 2)
>
low_evens = [2,4,6,8]
# make a list containing 11 - 99 odds only
big_odds = [x for x in list(xrange(100)) if x % 2 != 0 and x >9]
big_odds = range(11, 100, 2)
Erik Jones
Software Developer | Emma® er**@myemma.com
800.595.4401 or 615.292.5888
615.292.0777 (fax)
Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com
brad wrote:
low_odds = [1,3,5,7,9]
# make a list containing 10 - 98 evens only
big_evens = big_evens = [x for x in list(xrange(99)) if x % 2 ==
0 and x >8]
Why use xrange if you convert it to a full list in place? No
advantage there.
Regards,
Björn
--
BOFH excuse #300:
Digital Manipulator exceeding velocity parameters
Erik Jones wrote:
big_evens = range(10, 100, 2)
big_odds = range(11, 100, 2)
Neat, but not as clever or as hard to read as mine... I'll bet it faster
though... maybe not.
The upto part is here:
ok_numbers = low_odds + big_evens + [x for x in low_evens if x <= y] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: David Goodger |
last post by:
With apologies in advance to the devoutly religious among us, who may
be offended by this corruption of The Lord's Prayer. No offence
intended.
The Pythonista's Prayer
=======================...
|
by: serge calderara |
last post by:
Dear all,
I have an application which is suppose to start another executable process.
As soon as that process is running, I need to retrive its handle. The
problem of the particular process I am...
|
by: Max |
last post by:
Hi Folks,
I'm received this error on starting Control Center from the Start
menu....
db2javit.dll
This file does not have a program associated with it for performing
this action. Create an...
|
by: Sjaakie Helderhorst |
last post by:
Hi!
I use an ISDN monitor which displays caller ID. In stead of entering all
numbers manually, I wish to query a national phonenumber database, which I
obtained as a MySQL database. The only way...
|
by: juleni |
last post by:
Hello,
is there a possibility starting or stopping postgres database and
creating database instance by JAVA? Is there some API available for
this? If yes, can you please write some example, how...
|
by: Andrew Bullock |
last post by:
Hi,
code:
myClass x = new myClass();
x.dosomethingwith(x,y);
How do i make dosomethingwith(x,y) run on a separate thread, and then
inform the main thread when it has finished?
|
by: Arnie |
last post by:
We're using the ServiceController class provided by the .NET Framework,
programming in C#. We are using the Start() method to start a service from
another service. This works fine most of the...
|
by: Jim Langston |
last post by:
I know that functions starting with an underscore, or two underscores, are
reserved by the compiler/c++ and should not be used by the user and may
cause undefined behavior. My question is, how...
|
by: |
last post by:
Hi to everyone!
I have an Apache Webserver running on Win2000.
I try to start a console application an the server though PHP, with the
functions exec() or passthru() but it doesn't work.
The...
|
by: ropo |
last post by:
I have a .NET 2.0 app that at one point starts an old MFC App through
System.Diagnostics.Process.Start from a model form/
I then wait for it to finish by calling StartedProcess.WaitForExit();
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
| |