Quoting Max Noel <[EMAIL PROTECTED]>:
> Apparently, no. I just tried:
>
> >>> b = [i for i in range(10) if (i % 2) == 0 else 0]
You can sometimes do a bit of trickery with and/or. eg:
>>> odds = [(i % 2 == 1 and i or -1) for i in range(10)]
>>> odds
[-1, 1, -1, 3, -1, 5, -1, 7, -1, 9]
The b
On May 8, 2005, at 03:02, Bernard Lebel wrote:
> Hello,
>
> I just started using list comprehensions (loving them!)
>
> I know you can add an if statement, but can you put in there an else?
> I could not find an example of this.
>
Apparently, no. I just tried:
>>> b = [i for i in range(10
Hello,
I just started using list comprehensions (loving them!)
I know you can add an if statement, but can you put in there an else?
I could not find an example of this.
Thanks
Bernard
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mai
Okay,
I guess I was not being clear, or my example was not communicating the
situation of my code.
In function Test2, I am iterating through database tables (this is simulated
by the for loop across the range(1, 10), printing out a message that states
that I am operating on that particular table
On May 7, 2005, at 20:50, D. Hartley wrote:
> Ok, I hate to ask another question about this riddle. But I have
> looked and looked and looked.
>
> Where can I find more information on 'banner'? Everywhere I look it
> starts telling me about banner ads and so on, and that is not what I
> want!
>
At 09:22 AM 5/7/2005, Brian van den Broek wrote:
[snip]
global will indeed fix that, yes. But, I've been lead to believe that
one's first thought when tempted to write a global statement should be
to reflect on whether that temptation isn't the symptom of a
sub-optimal design. It certainly can
> while x < 26:
> new_alph = alph[1:] + alph[:1]
> print new_alph
> print "\n"
> x += 1
>
> But this has the drawback of not progressing with my
> newly create alphabet, it just returns:
> abcdefghijklmnopqrstuvwxyz
The reason that new_alph never changes is that you are calculating
> On May 7, 2005, at 13:17, John Carmona wrote:
>
> > Hi to everybody reading this thread, can anybody point me to the URL
> > where I can find these challenges. Many thanks
Hi John,
By the way, just to make sure you know, the mailing list here has an
archive here:
http://mail.python.org/
Ok, I hate to ask another question about this riddle. But I have
looked and looked and looked.
Where can I find more information on 'banner'? Everywhere I look it
starts telling me about banner ads and so on, and that is not what I
want!
Any howto's/tutorials/simple explanations would be apprecia
On Sat, 2005-05-07 at 12:56 -0400, Michael wrote:
> Tanja, Bob, Brian,
>
> Many thanks for your help.
>
> And perhaps the way in which I posed the question was misleading. In a
> process I am writing, I was actually trying not to use global variables, as
> I agree with Brian. However, I inadv
Tanja, Bob, Brian,
Many thanks for your help.
And perhaps the way in which I posed the question was misleading. In a
process I am writing, I was actually trying not to use global variables, as
I agree with Brian. However, I inadvertantly used a variable within a 'def'
block that I had used ou
Bob Gailer said unto the world upon 2005-05-07 11:46:
> At 07:43 AM 5/7/2005, Brian van den Broek wrote:
>
>> [EMAIL PROTECTED] said unto the world upon
>> 2005-05-07 09:56:
>> > Good morning,
>> >
>> > I came across a rather odd issue with scoping. Can someone explain why
>> > testa and testc wo
At 07:43 AM 5/7/2005, Brian van den Broek wrote:
[EMAIL PROTECTED]
said unto the world upon
2005-05-07 09:56:
> Good morning,
>
> I came across a rather odd issue with scoping. Can someone
explain why
> testa and testc works, but not testb. I am running under
python 2.4.1 on
> Windows NT.
>
[EMAIL PROTECTED] said unto the world upon
2005-05-07 09:56:
> Good morning,
>
> I came across a rather odd issue with scoping. Can someone explain why
> testa and testc works, but not testb. I am running under python 2.4.1 on
> Windows NT.
>
> thanks,
> Michael
> def testb(astr):
> x
On 7 Mai 2005, [EMAIL PROTECTED] wrote:
> I came across a rather odd issue with scoping. Can someone explain why
> testa and testc works, but not testb. I am running under python 2.4.1 on
[...]
> x = 5
>
> def testa(astr):
> print astr, x
>
> testa(22)
>
> def testb(astr):
> x = x - 1
hi Michael,
in Python, names are not declared ahead of time so Python uses the
assigment of a name to "bind" it to a particular namespace.
you first assigned a "global" x with the value of 5.
in your testa and testc functions, you are only using variable x, and
because x is already assigned globa
On May 7, 2005, at 15:06, Max Noel wrote:
> Try the following code:
>
>
>
> for i in neverEndingTest():
> print i
>
Sorry, i meant "for in in neverEndingStatus()" (not
neverEndingTest()), where neverEndingStatus is the function I gave as
an example in my previous post (not you
On May 7, 2005, at 13:17, John Carmona wrote:
> Hi to everybody reading this thread, can anybody point me to the
> URL where I can find these challenges. Many thanks
>
> JC
>
http://www.pythonchallenge.com/
-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathe
On May 7, 2005, at 13:22, John Clark wrote:
> (Either that, or I am not following what you mean when you say:
>
>
>> As for how to access it, use a for loop (for i in
>> neverEndingStatus()). xrange, for example, is a generator function.
>>
>
> Can you please provide an example of how my Tes
On 7 Mai 2005, [EMAIL PROTECTED] wrote:
> It's clear that your code is a more elegant implementation of
> neverEndingStatus() but I am still having to initialize a global variable
> and call .next() when I want to get the next value... So the generator
> function has been cleaned up, but the clie
Good morning,
I came across a rather odd issue with scoping. Can someone explain why
testa and testc works, but not testb. I am running under python 2.4.1 on
Windows NT.
thanks,
Michael
x = 5
def testa(astr):
print astr, x
testa(22)
def testb(astr):
x = x - 1
print astr, x
Okay, take two...
import sys
def neverEndingStatus():
def statusGen():
index = 0
statusChars = ['|', '\\', '-', '/']
while True:
yield statusChars[index]
index = (index + 1) % 4
try:
neverEndingStatus.x
except A
Ooops - sorry - I spoke too soon...
It's clear that your code is a more elegant implementation of
neverEndingStatus() but I am still having to initialize a global variable
and call .next() when I want to get the next value... So the generator
function has been cleaned up, but the client code inter
Hi to everybody reading this thread, can anybody point me to the URL where I
can find these challenges. Many thanks
JC
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Quoting John Clark <[EMAIL PROTECTED]>:
> import sys
>
> def neverEndingStatus(currentChar_ = '|'):
> while 1:
> if currentChar_ == '|':
>currentChar_ = '\\'
> elif currentChar_ == '\\':
>currentChar_ = '-'
> elif currentChar_ == '-':
>currentChar_ = '/'
> elif currentChar_
Lightbulb!
It's clear that I don't yet fully understand the power of generator
functions... It never occurred to me to yield out of the middle of a loop,
and yet, seeing your code, it's obvious that that's one of the primary
purposes of "yield".
Thanks,
-jdc
On 5/7/05 8:00 AM, "Max Noel" <[EMAI
On May 7, 2005, at 12:28, John Clark wrote:
> My question - the creation of the global variable x seems kludged -
> when I
> first started with this I thought I was going to be coding
> something like
> sys.stderr.write('\b'+neverEndingStatus()) but that just returns
> '\' each
> time and I
Hello,
I am working on learning Python and writing some console applications to
apply what I am learning - I am using a generator function to implement a
status indicator as follows:
import sys
def neverEndingStatus(currentChar_ = '|'):
while 1:
if currentChar_ == '|':
> alph =
["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","
r","s","t","u","v","w","x","y","z"]
import string
alph = string.lowercase
> print "\n"
> print alph
> print "\n"
print '\n%s\n' % alph
> x = 1
> while x < 26:
for letter in alph:
> alph.append(alph.pop(0))
>
Quoting Max Russell <[EMAIL PROTECTED]>:
> anyway- I don't like the output which come in the
> form:
> ['b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
> 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
> 'w', 'x', 'y', 'z', 'a']
>
>
> What I'd like to do is take my list and turn it into
hi Max,
you can use:
alph = ["a","b", ]
myString = "".join(alph)
print myString
regards,
tanja
On 5/7/05, Max Russell <[EMAIL PROTECTED]> wrote:
> Hello-
>
> I've started writing a suite of tools to help me do
> Crypto puzzles (slowly...) My first snippet of code
> allos me to print out a
Hello-
I've started writing a suite of tools to help me do
Crypto puzzles (slowly...) My first snippet of code
allos me to print out a Caesar shifting alphabet, as I
tend to write them out by hand; which is a waste of
time.
alph =
["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","
32 matches
Mail list logo