Neil Cerutti <[EMAIL PROTECTED]> writes:
> i = 0
> while i < self.parent.GetPageCount():
> # do stuff
> i += 1
Alternatively:
from itertools import count
for i in count():
if i >= self.parent.GetPageCount():
break
...
--
http://mail.python.org/mailman/listinfo
On 2007-08-27, Neil Cerutti <[EMAIL PROTECTED]> wrote:
> This sort of suggests a direct solution:
>
> for i in xrange(self.parent.GetPageCount()):
> if i >= self.parent.GetPageCount():
> break
> # do stuff
>
> At least that way you're spared the manual manipulation of i.
On second thought,
On 2007-08-27, bambam <[EMAIL PROTECTED]> wrote:
> Thank you, I have been through the tutorial several times, I
> guess I'm just not smart enough. Perhaps I have been led astray
> by what I read here?
>
> My code started like this:
>
> for i in range(self.parent.GetPageCount()):
>
> I was asked:
>
bambam a écrit :
> Thank you, I have been through the tutorial several times, I guess
> I'm just not smart enough. Perhaps I have been led astray by what
> I read here?
>
> My code started like this:
>
> for i in range(self.parent.GetPageCount()):
>
> I was asked:
>
>> Does page count change? i
Thank you. I figured the set would probably be faster,
but the lists are small, and I'm concerned that the code
is going to look Byzantine if I keep swapping between
lists, sets and dictionaries :~).
At the moment there are no sets or dictionaries in the
entire code base I am working with. I'm not
Thank you.
Steve.
"Alex Martelli" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> bambam <[EMAIL PROTECTED]> wrote:
>
>> Is it safe to write
>>
>> A = [x for x in A if x in U]
>>
>> or is that undefined? I understand that the slice operation
>
> It's perfectly safe and well-defined
"bambam" <[EMAIL PROTECTED]> writes:
> Is it safe to write
> A = [x for x in A if x in U]
> or is that undefined? I understand that the slice operation
> can be used to make a temporary copy, so I could write
> A=[x for x in A[:] if x in U]
> but I've just copied that without any understanding.
Yo
bambam <[EMAIL PROTECTED]> wrote:
...
> Bags don't seem to be built in to my copy of Python, and
A "bag" is a collections.defaultdict(int) [[you do have to import
collections -- it's in the standard library, NOT built-in]].
Alex
--
http://mail.python.org/mailman/listinfo/python-list
bambam <[EMAIL PROTECTED]> wrote:
> Is it safe to write
>
> A = [x for x in A if x in U]
>
> or is that undefined? I understand that the slice operation
It's perfectly safe and well-defined, as the assignment rebinds the LHS
name only AFTER the RHS list comprehension is done.
Alex
--
http://
Is it safe to write
A = [x for x in A if x in U]
or is that undefined? I understand that the slice operation
can be used to make a temporary copy, so I could write
A=[x for x in A[:] if x in U]
but I've just copied that without any understanding.
Steve.
"bambam" <[EMAIL PROTECTED]> wrote in
Thank you, I have been through the tutorial several times, I guess
I'm just not smart enough. Python is quite different from the
languages I am familiar with.
My code sample started like this:
>>for i in range(self.parent.GetPageCount()):
I was asked:
>Does page count change? i.e. is it necessa
Thank you, I have been through the tutorial several times, I guess
I'm just not smart enough. Perhaps I have been led astray by what
I read here?
My code started like this:
for i in range(self.parent.GetPageCount()):
I was asked:
>Does page count change? i.e. is it necessary to retrieve it in e
bambam wrote:
> That is, is it defined what Python does for
> for i in f()
> I'm sure it must be, but I haven't seen it yet. If I have
> a user defined function returning a range, is it defined
> that the range function is called on every loop? If I
> have a function returning a range taking a
En Sun, 26 Aug 2007 22:58:35 -0300, bambam <[EMAIL PROTECTED]> escribi�:
> Ok, many environments are capable of cached evaluation
> of functions without variable parameters so
> range(5)
> is cached, but
> range(v) is re-evaluated every time. Is this defined
> behaviour?
The range builtin
Ok, many environments are capable of cached evaluation
of functions without variable parameters so
range(5)
is cached, but
range(v) is re-evaluated every time. Is this defined
behaviour?
That is, is it defined what Python does for
for i in f()
I'm sure it must be, but I haven't seen it
c = sorted(set(a)-set(b))
although for me :~( that is another step more obscure than
c = list(set(a)-set(b))
c.sort()
Bags don't seem to be built in to my copy of Python, and
although I'm interested in why lists don't support the difference
operation, I don't want to get away from standard Pyth
That looks good, and perhaps a difference operator
would be too simple to be useful anyway.
Steve.
"Mikael Olofsson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
>
> bambam wrote:
>>
>> In this case it doesn't matter - my lists don't contain
>> duplicate elements this time - but
On Aug 23, 11:50 pm, "bambam" <[EMAIL PROTECTED]> wrote:
> Thank you, so generallizing:
>
> (1) Python re-evaluates the loop range on every loop, and
> (2) Python does short-circuit evaluation of conditions, in predictable
> order.
>
> Sorry about the bad question.
>
A beginner would do well to wo
bambam wrote:
>> The reason that lists don't have set-like methods is because
>> lists aren't sets -- lists can contain duplicate elements
and they are ordered. I'd have used sets if I was sure you
meant [1,2,3] to mean the same thing as [3,1,2] and no duplicates.
> Interesting point -- if that's
bambam wrote:
>
> In this case it doesn't matter - my lists don't contain
> duplicate elements this time - but I have worked with lists in
> money market and in inventory, and finding the intersection
> and difference for matching off and netting out are standard
> operations.
I would use a list
> This isn't a "cast" in the sense of some less-strongly-typed languages;
> it's just a conversion. The `list` function/type iterates over its
> argument and turns it into a list. Sets are iterable, so that's all
> that's really going on here.
oh :~). Learning experience happening here... Tha
bambam wrote:
> Excellent. By symmetry, I see that "list" casts the set back into a list.
>
> I wonder why list has not been extended with the same (difference,
> interesection) methods? Casting to set looks a little kludgy:
>
> c = list(set(a)-set(b))
> I wonder if that is clearer than the exp
Excellent. By symmetry, I see that "list" casts the set back into a list.
I wonder why list has not been extended with the same (difference,
interesection) methods? Casting to set looks a little kludgy:
c = list(set(a)-set(b))
I wonder if that is clearer than the explicit loop?
Steve.
"Gabrie
Wos! Several different thoughts:
An object using yield to return only the relevant pages, one at a time.
Pop to remove the items from the list.
A dictionary to map between the strings and the integers.
The dictionary was particularly unexpected. Eventually, I
plan to change the string ports to de
Thank you, so generallizing:
(1) Python re-evaluates the loop range on every loop, and
(2) Python does short-circuit evaluation of conditions, in predictable
order.
Sorry about the bad question.
"Zentrader" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Does page count change?
En Thu, 23 Aug 2007 23:54:14 -0300, bambam <[EMAIL PROTECTED]> escribi�:
> After examining your suggestion, I realised that another thing
> I am interested in could be generalised: I want the complement
> of the set of ports in pages, given a universal set in tempList.
> Ignoring the break conditi
Wos! Several different thoughts:
An object using yield to return only the relevant pages, one at a time.
Pop to remove the items from the list.
A dictionary to map between the strings and the integers.
The dictionary was particularly unexpected. Eventually, I
plan to change the string ports to de
Does page count change? i.e. is it necessary to retrieve it in every
loop or
tempList = ['1','2','3','4','5','6','7','8']
sampleList=[]
page_count = self.parent.GetPageCount()
for i in range(page_count):
Also, once pagefound is set to True, all pages following will not be
appended to sampleL
bambam wrote:
> Would someone like to suggest a replacement for this? It works ok,
> but it doesn't look like any of the other code:
>
> tempList = ['1','2','3','4','5','6','7','8']
> sampleList=[]
> for port in tempList:
> pagefound = False
> for i in range(self.parent.GetPageCount()):
>
Would someone like to suggest a replacement for this? It works ok,
but it doesn't look like any of the other code:
tempList = ['1','2','3','4','5','6','7','8']
sampleList=[]
for port in tempList:
pagefound = False
for i in range(self.parent.GetPageCount()):
page=self.parent.GetPage
30 matches
Mail list logo