Re: [Tutor] For Loop

2015-10-30 Thread Danny Yoo
On Fri, Oct 30, 2015 at 10:48 AM, Martin A. Brown wrote: > > Hello Shelby, > >> I was wondering if someone can complete a for loop in an array for >> me. > > Your question is a bit too terse. You don't give us too much detail > in understanding what you want to do. Also, we have no idea *why* y

Re: [Tutor] For Loop

2015-10-30 Thread Martin A. Brown
Hello Shelby, > I was wondering if someone can complete a for loop in an array for > me. Your question is a bit too terse. You don't give us too much detail in understanding what you want to do. But, we are the Tutor list and we are here to help! Here are a few things which may help you get

Re: [Tutor] For Loop

2015-10-30 Thread Alan Gauld
On 30/10/15 01:27, Shelby Neely wrote: Hi, I was wondering if someone can complete a for loop in an array for me. for item in anArray: print(item) If that doesn't help then you are going to have to explain more about what exactly you want to know. Show us your code, explain what you expected t

[Tutor] For Loop

2015-10-30 Thread Shelby Neely
Hi, I was wondering if someone can complete a for loop in an array for me. Thank you ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] for loop for long numbers

2015-08-04 Thread Dima Kulik
I want to ask user how many time he would like to make an iteration of crypt function. Also if he/she wants to do it numerous times, my code should work. So i use such code: x = input("How many time you want to encrypt?") for i in xrange(0,x+1):  make_code of course i can make rule to prevent f

Re: [Tutor] for loop for long numbers

2015-08-04 Thread Peter Otten
Peter Otten wrote: > But note that if some_code() takes 1 microsecond the loop will run for > about Sorry, that should be millisecond (1/1000 s). 90/60/60/24/1000 > 104.17 > > 104 days. ___ Tutor maillist - Tutor@python.

Re: [Tutor] for loop for long numbers

2015-08-03 Thread Peter Otten
Dima Kulik wrote: > I want to make a for loop with a huge numbers. > for example: > > for i in range (0,90): some_code() > but range and xrange cant operate with such big numbers. > Can some on help me? If you are just beginning with Python and do not require any libraries that are

Re: [Tutor] for loop for long numbers

2015-08-03 Thread eryksun
On Mon, Aug 3, 2015 at 8:50 PM, Steven D'Aprano wrote: > If you have a 64-bit operating system, you can use a 64-bit version of > Python, and the limit will be something like 2**63 - 1 or so. I can't > test this myself, as I have a 32-bit system like you. A notable exception to the above claim is

Re: [Tutor] for loop for long numbers

2015-08-03 Thread Steven D'Aprano
On Mon, Aug 03, 2015 at 09:15:45PM +0300, Dima Kulik wrote: > Hi to all. > Can you help me plz. > I want to make a for loop with a huge numbers. > for example: > > for i in range (0,90): >  make_some_code > > but range and xrange cant operate with such big numbers. In Python 2, range(

Re: [Tutor] for loop for long numbers

2015-08-03 Thread Danny Yoo
> Hi to all. > Can you help me plz. > I want to make a for loop with a huge numbers. > for example: > > for i in range (0,90): > make_some_code Can you say more why you are trying to do this, by the way? Without context, this request seems strange, as we often want to make our programs

Re: [Tutor] for loop for long numbers

2015-08-03 Thread Martin A. Brown
Greetings Dima, Can you help me plz. I want to make a for loop with a huge numbers. for example: for i in range (0,90):  make_some_code but range and xrange cant operate with such big numbers. Can some on help me? Ah, range and xrange. It would help us to know which Python version

Re: [Tutor] for loop for long numbers

2015-08-03 Thread Mark Lawrence
On 03/08/2015 19:15, Dima Kulik wrote: Hi to all. Can you help me plz. I want to make a for loop with a huge numbers. for example: for i in range (0,90): make_some_code but range and xrange cant operate with such big numbers. Can some on help me? Thanks. You cannot do anything ab

Re: [Tutor] for loop for long numbers

2015-08-03 Thread Alan Gauld
On 03/08/15 19:15, Dima Kulik wrote: I want to make a for loop with a huge numbers. for example: for i in range (0,90): make_some_code but range and xrange cant operate with such big numbers. What makes you think so? Did you try? What error did you get? And what version of python w

[Tutor] for loop for long numbers

2015-08-03 Thread Dima Kulik
Hi to all. Can you help me plz. I want to make a for loop with a huge numbers. for example: for i in range (0,90):  make_some_code but range and xrange cant operate with such big numbers. Can some on help me? Thanks. -- Dima Kulik ___ Tutor

Re: [Tutor] For Loop Question

2012-12-24 Thread Alan Gauld
On 24/12/12 16:31, bob gailer wrote: On 12/23/2012 9:02 PM, Alan Gauld wrote: You do realize that self is only defined inside a method? Perhaps. self is just another name - it could be "just" a variable, outside any method. True enough, but given the usage "self.A" it looks pretty certain

Re: [Tutor] For Loop Question

2012-12-24 Thread bob gailer
On 12/23/2012 9:02 PM, Alan Gauld wrote: You do realize that self is only defined inside a method? Perhaps. self is just another name - it could be "just" a variable, outside any method. -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor mailli

Re: [Tutor] For Loop Question

2012-12-23 Thread Dave Angel
On 12/23/2012 09:02 PM, Alan Gauld wrote: > On 24/12/12 01:16, Mitya Sirenef wrote: >> On 12/23/2012 08:03 PM, Tom Tucker wrote: >>> >>> >>> Python Gurus, >>> I got a question for ya. Below I have three instance variables >>> (self.A, self.B, etc). How can I use the below >>> for loop for A, B, C

Re: [Tutor] For Loop Question

2012-12-23 Thread Alan Gauld
On 24/12/12 01:16, Mitya Sirenef wrote: On 12/23/2012 08:03 PM, Tom Tucker wrote: Python Gurus, I got a question for ya. Below I have three instance variables (self.A, self.B, etc). How can I use the below for loop for A, B, C to also call those instance variables? Your example is not ent

Re: [Tutor] For Loop Question

2012-12-23 Thread Mitya Sirenef
On 12/23/2012 08:03 PM, Tom Tucker wrote: Python Gurus, I got a question for ya. Below I have three instance variables (self.A, self.B, etc). How can I use the below for loop for A, B, C to also call those instance variables? Example ### . . self.A = 1 self.

[Tutor] For Loop Question

2012-12-23 Thread Tom Tucker
Python Gurus, I got a question for ya. Below I have three instance variables (self.A, self.B, etc). How can I use the below for loop for A, B, C to also call those instance variables? Example ### . . self.A = 1 self.B= 2 self.C= 3 myDict = {'A': 1, 'B':

Re: [Tutor] for loop question

2012-07-04 Thread Emile van Sebille
On 7/1/2012 2:50 PM Jim said... Hello Friends, I apologize for being such a bother. This problem has been evading me all day. Can you please give me a hint as to why I cannot put the variable UpperCaseSentence outside of the for loop? I can do it in other instances but not in this one. Thank you

Re: [Tutor] for loop question

2012-07-04 Thread Hugo Arts
On Sun, Jul 1, 2012 at 11:50 PM, Jim wrote: > Hello Friends, > I apologize for being such a bother. This problem has been evading me all > day. Can you please give me a hint as to why I cannot put the variable > UpperCaseSentence outside of the for loop? > I can do it in other instances but not i

[Tutor] for loop question

2012-07-04 Thread Jim
Hello Friends, I apologize for being such a bother. This problem has been evading me all day. Can you please give me a hint as to why I cannot put the variable UpperCaseSentence outside of the for loop? I can do it in other instances but not in this one. Thank you so much, Jim #Main function.

Re: [Tutor] for loop results into list

2010-09-05 Thread Micheal Beatty
On 09/05/2010 03:48 PM, Evert Rol wrote: On 5 Sep 2010, at 22:31 , Micheal Beatty wrote: On 09/05/2010 03:16 PM, Evert Rol wrote: I'm having a little problem figuring out how to accomplish this simple task. I'd like to take a list of 6 numbers and add every permutation of those numbers in g

Re: [Tutor] for loop results into list

2010-09-05 Thread Evert Rol
On 5 Sep 2010, at 22:31 , Micheal Beatty wrote: > On 09/05/2010 03:16 PM, Evert Rol wrote: >>> I'm having a little problem figuring out how to accomplish this simple >>> task. I'd like to take a list of 6 numbers and add every permutation of >>> those numbers in groups of four. For

Re: [Tutor] for loop results into list

2010-09-05 Thread Micheal Beatty
On 09/05/2010 03:16 PM, Evert Rol wrote: I'm having a little problem figuring out how to accomplish this simple task. I'd like to take a list of 6 numbers and add every permutation of those numbers in groups of four. For example for 1, 2, 3, 4, 5, 6 add 1 + 1 + 1 +1 then 1 + 1 + 1 +2 etc. unt

Re: [Tutor] for loop results into list

2010-09-05 Thread Evert Rol
> > I'm having a little problem figuring out how to accomplish this simple > task. I'd like to take a list of 6 numbers and add every permutation of > those numbers in groups of four. For example for 1, 2, 3, 4, 5, 6 add 1 + > 1 + 1 +1 then 1 + 1 + 1 +2 etc. until reaching 6 + 6

Re: [Tutor] for loop results into list

2010-09-05 Thread Micheal Beatty
On 09/05/2010 02:22 PM, Evert Rol wrote: I'm having a little problem figuring out how to accomplish this simple task. I'd like to take a list of 6 numbers and add every permutation of those numbers in groups of four. For example for 1, 2, 3, 4, 5, 6 add 1 + 1 + 1 +1 then 1 + 1 + 1 +2 etc. unt

Re: [Tutor] for loop results into list

2010-09-05 Thread Evert Rol
>>> I'm having a little problem figuring out how to accomplish this simple >>> task. I'd like to take a list of 6 numbers and add every permutation of >>> those numbers in groups of four. For example for 1, 2, 3, 4, 5, 6 add 1 + 1 >>> + 1 +1 then 1 + 1 + 1 +2 etc. until reaching 6 + 6 + 6 + 6. U

Re: [Tutor] for loop results into list

2010-09-05 Thread Andre Engels
On Sun, Sep 5, 2010 at 8:51 PM, Micheal Beatty wrote: >  On 09/05/2010 01:26 PM, Evert Rol wrote: >>> >>> Hello all, >>> >>> I'm having a little problem figuring out how to accomplish this simple >>> task. I'd like to take a list of 6 numbers and add every permutation of >>> those numbers in group

Re: [Tutor] for loop results into list

2010-09-05 Thread Micheal Beatty
On 09/05/2010 01:26 PM, Evert Rol wrote: Hello all, I'm having a little problem figuring out how to accomplish this simple task. I'd like to take a list of 6 numbers and add every permutation of those numbers in groups of four. For example for 1, 2, 3, 4, 5, 6 add 1 + 1 + 1 +1 then 1 + 1 + 1

Re: [Tutor] for loop results into list

2010-09-05 Thread Evert Rol
> Hello all, > > I'm having a little problem figuring out how to accomplish this simple task. > I'd like to take a list of 6 numbers and add every permutation of those > numbers in groups of four. For example for 1, 2, 3, 4, 5, 6 add 1 + 1 + 1 +1 > then 1 + 1 + 1 +2 etc. until reaching 6 + 6 +

[Tutor] for loop results into list

2010-09-05 Thread Micheal Beatty
Hello all, I'm having a little problem figuring out how to accomplish this simple task. I'd like to take a list of 6 numbers and add every permutation of those numbers in groups of four. For example for 1, 2, 3, 4, 5, 6 add 1 + 1 + 1 +1 then 1 + 1 + 1 +2 etc. until reaching 6 + 6 + 6 + 6. Usi

Re: [Tutor] For loop breaking string methods

2010-04-27 Thread bob gailer
On 4/26/2010 10:19 PM, Dave Angel wrote: Note also that if you insert or delete from the list while you're looping, you can get undefined results. The results are not undefined. They m,ight be unexpected, but that is due to an invalid assumption. The behavior is explained in section 7.3

Re: [Tutor] For loop breaking string methods

2010-04-27 Thread Lie Ryan
On 04/27/10 12:19, Dave Angel wrote: > Note also that if you insert or delete from the list while you're > looping, you can get undefined results. That's one reason it's common > to build a new loop, and just assign it back when done. Example would > be the list comprehension you showed earlier.

Re: [Tutor] For loop breaking string methods

2010-04-26 Thread Dave Angel
C M Caine wrote: Thank you for the clarification, bob. For any future readers of this thread I include this link[1] to effbot's guide on lists, which I probably should have already read. My intention now is to modify list contents in the following fashion: for index, value in enumerate(L):

Re: [Tutor] For loop breaking string methods

2010-04-26 Thread C M Caine
On 26 April 2010 23:45, Alan Gauld wrote: > > "C M Caine" wrote >> >> My intention now is to modify list contents in the following fashion: >> >> for index, value in enumerate(L): >>   L[0] = some_func(value) > > I think you mean: >     L[index] = some_func(value) Yes, I do >> Is this the stand

Re: [Tutor] For loop breaking string methods

2010-04-26 Thread C M Caine
>> What other strange behaviour should I expect from for loops? > > You should read up on immutable data types like strings and tuples. > Start with [1]. > > Greets > Sander > > [1] http://docs.python.org/reference/datamodel.html > Thank you kindly for your reply, I'll be sure to read up on it. C

Re: [Tutor] For loop breaking string methods

2010-04-26 Thread Alan Gauld
"C M Caine" wrote My intention now is to modify list contents in the following fashion: for index, value in enumerate(L): L[0] = some_func(value) I think you mean: L[index] = some_func(value) Is this the standard method? Or use a List copmprehension. L = [some_func(value) for

Re: [Tutor] For loop breaking string methods

2010-04-26 Thread Sander Sweers
On 26 April 2010 21:38, C M Caine wrote: > Why does this not work: L = [' foo ','bar '] for i in L: >     i = i.strip() str.strip() _returns_ a *new* string and leaves the original string alone. The reason being that string are immutable so can not be changed. >>> s1 = ' foo ' >>> s1[1

Re: [Tutor] For loop breaking string methods

2010-04-26 Thread C M Caine
Thank you for the clarification, bob. For any future readers of this thread I include this link[1] to effbot's guide on lists, which I probably should have already read. My intention now is to modify list contents in the following fashion: for index, value in enumerate(L): L[0] = some_func(v

Re: [Tutor] For loop breaking string methods

2010-04-26 Thread bob gailer
On 4/26/2010 3:38 PM, C M Caine wrote: Why does this not work: By "work" you mean "do what I want it to do". >>> L = [' foo ','bar '] >>> for i in L: i = i.strip() This creates a new local variable named i. It does not affect L. This has nothing to do with loops nor is it strange behav

[Tutor] For loop breaking string methods

2010-04-26 Thread C M Caine
Why does this not work: >>> L = [' foo ','bar '] >>> for i in L: i = i.strip() >>> L [' foo ', 'bar '] >>> # note the leading whitespace that has not been removed. But this does: >>> L = [i.strip() for i in L] >>> L ['foo', 'bar'] What other strange behaviour should I expect from for loops?

Re: [Tutor] for loop issue

2009-10-12 Thread Stefan Lesicnik
> Thanks for the tip on enumerate, escaped me. Much like Kent's simply > using a temporary var escaped me despite having done similar things > often... never reply on a tiring Friday. On the bright side this > blunder with indexes, iterators, and lengths has made me more aware of > other contexts f

Re: [Tutor] for loop issue

2009-10-10 Thread Oxymoron
On Sun, Oct 11, 2009 at 4:07 AM, Rich Lovely wrote: > for i, v in enumerate(x[:-1]):  #omitting last value in list to avoid > IndexError >   print v, x[i+1] Thanks for the tip on enumerate, escaped me. Much like Kent's simply using a temporary var escaped me despite having done similar things of

Re: [Tutor] for loop issue

2009-10-10 Thread Rich Lovely
2009/10/9 Oxymoron : > On Fri, Oct 9, 2009 at 11:02 PM, Kent Johnson wrote: >> On Fri, Oct 9, 2009 at 3:54 AM, Stefan Lesicnik wrote: >> >> You can easily keep track of the previous item by assigning it to a >> variable. For example this shows just the increasing elements of a >> sequence: >> >>

Re: [Tutor] for loop issue

2009-10-09 Thread Oxymoron
On Fri, Oct 9, 2009 at 11:02 PM, Kent Johnson wrote: > On Fri, Oct 9, 2009 at 3:54 AM, Stefan Lesicnik wrote: > > You can easily keep track of the previous item by assigning it to a > variable. For example this shows just the increasing elements of a > sequence: > > In [22]: items = [0, 1, 3, 2,

Re: [Tutor] for loop issue

2009-10-09 Thread Kent Johnson
On Fri, Oct 9, 2009 at 3:54 AM, Stefan Lesicnik wrote: > Hi, > > This feels like a strange issue, so i hope I formulate this so its > understandable. > > I have some objects. Each object has associated values. I am looping > through these objects, working with a value and printing out the > value.

Re: [Tutor] for loop issue

2009-10-09 Thread Oxymoron
On Fri, Oct 9, 2009 at 9:35 PM, Oxymoron wrote: > Thus, you can muck around with x[i] (current item), and x[i+1] (next > item), and decide how you want to proceed with the loop. Note the use > of len(x) - 1 rather than just len(x) to easily prevent an IndexError > or extra special case logic. "ea

Re: [Tutor] for loop issue

2009-10-09 Thread Oxymoron
Hello, On Fri, Oct 9, 2009 at 6:54 PM, Stefan Lesicnik wrote: > The issue in this case is that i need to check if the one value > superseeds the other, and in that case, not print it out. I think the > problem is that when you are in the loop, you dont know about the > other object that you haven

[Tutor] for loop issue

2009-10-09 Thread Adam Bark
2009/10/9 Stefan Lesicnik Hi, > > This feels like a strange issue, so i hope I formulate this so its > understandable. > > I have some objects. Each object has associated values. I am looping > through these objects, working with a value and printing out the > value. > The issue in this case is t

[Tutor] for loop issue

2009-10-09 Thread Stefan Lesicnik
Hi, This feels like a strange issue, so i hope I formulate this so its understandable. I have some objects. Each object has associated values. I am looping through these objects, working with a value and printing out the value. The issue in this case is that i need to check if the one value super

Re: [Tutor] for loop

2009-04-16 Thread W W
On Thu, Apr 16, 2009 at 3:45 PM, mbikinyi brat wrote: > Dear ALL, > I am a beginner in python and I just copied the code in blue below and > execute and had the result in green. Then I thought *letter* should be a > special word in python. Then I now replace letter whith *chic* and yet > the same

Re: [Tutor] for loop

2009-04-16 Thread R. Alan Monroe
for letter in "python": >  print "Current letter:", letter for chic in "python": >  print "chic:", chic When you write a for-in loop, you can use any variable name you feel like using (letter, chic, mycoolvariable, x, etc.) It's that simple :) Alan __

Re: [Tutor] for loop

2009-04-16 Thread Alan Gauld
"mbikinyi brat" wrote Then I thought letter should be a special word in python. Why did you think that? Python has a very specific (and small) set of keywords that have special meaning - things like for, while and print But you can call variables pretty much whatever you like and Python

Re: [Tutor] for loop

2009-04-16 Thread Emile van Sebille
mbikinyi brat wrote: Dear ALL, I am a beginner in python and I just copied the code in blue below and execute and had the result in green. Then I thought *letter* should be a special word in python. Then I now replace letter whith *chic* and yet the same results is obtained. of course -- c

[Tutor] for loop

2009-04-16 Thread mbikinyi brat
Dear ALL, I am a beginner in python and I just copied the code in blue below and execute and had the result in green. Then I thought letter should be a special word in python. Then I now replace letter whith chic  and yet the same results is obtained. I cannot reconcile them. Can someone explain

Re: [Tutor] For Loop question

2008-06-27 Thread Kent Johnson
On Fri, Jun 27, 2008 at 2:45 AM, Mark Tolonen <[EMAIL PROTECTED]> wrote: > The above solutions create new lists. If a functional requirement is to > modify the list in place, then the original is fine (on Python 2.6 and > later) or should use xrange instead of range (on Python 2.5 or earlier, > e

Re: [Tutor] For Loop question

2008-06-26 Thread Mark Tolonen
"Lie Ryan" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] On Thu, Jun 26, 2008 at 3:18 AM, Dick Moores <[EMAIL PROTECTED]> wrote:  Hi I'm learning FOR loop now, very easy too learn. But I get confused to understand this code : myList = [1,2,3,4] for index in range(len(myList)):

Re: [Tutor] For Loop question

2008-06-26 Thread Lie Ryan
On Thu, Jun 26, 2008 at 3:18 AM, Dick Moores <[EMAIL PROTECTED]> wrote: > Hi I'm learning FOR loop now, very easy too learn. But I get confused > to understand this code : > > myList = [1,2,3,4] > for index in range(len(myList)): > myList[index] += 1 > print myList > > And the response is: >

Re: [Tutor] For Loop question

2008-06-26 Thread Cédric Lucantis
Le Thursday 26 June 2008 15:27:05 Danny Laya, vous avez écrit : > Hi I'm learning FOR loop now, very easy too learn. But I get confused to > understand this code : myList = [1,2,3,4] > for index in range(len(myList)): > myList[index] += 1 > print myList > > And the response is: > [2, 3, 4, 5] >

Re: [Tutor] For Loop question

2008-06-26 Thread bhaaluu
On Thu, Jun 26, 2008 at 9:27 AM, Danny Laya <[EMAIL PROTECTED]> wrote: > Hi I'm learning FOR loop now, very easy too learn. But I get confused to > understand this code : > > myList = [1,2,3,4] > for index in range(len(myList)): > myList[index] += 1 > print myList > > And the response is: > [2,

[Tutor] For Loop question

2008-06-26 Thread Danny Laya
Hi I'm learning FOR loop now, very easy too learn. But I get confused to understand this code : myList = [1,2,3,4] for index in range(len(myList)): myList[index] += 1 print myList And the response is: [2, 3, 4, 5] Can you explain me as a newbie, how that code works ?? _

Re: [Tutor] for loop

2008-06-10 Thread Alan Gauld
"Tiago Saboga" <[EMAIL PROTECTED]> wrote The count var is never updated. What about: for i in someArray[1:]: print i Yes, that's much better than my enumerate version! :-) Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org

Re: [Tutor] for loop

2008-06-10 Thread Alan Gauld
"Sean Novak" <[EMAIL PROTECTED]> wrote I would normally write this in PHP like this: for($i=1; i< count($someArray); $i++) { print $someArray[i] } essentially,, I want to loop through an array skipping "someArray[0]" for i,n in enumerate(myArray): if i == 0: continue print n is how

Re: [Tutor] for loop

2008-06-10 Thread Martin Walsh
Sean Novak wrote: > I know I'm going to feel stupid on this one.. > I would normally write this in PHP like this: > > for($i=1; i< count($someArray); $i++) > { > print $someArray[i] > } > > essentially,, I want to loop through an array skipping "someArray[0]" > but in python the for syntax is

Re: [Tutor] for loop

2008-06-10 Thread Tiago Saboga
On Tue, Jun 10, 2008 at 09:36:47PM -0400, Sean Novak wrote: > I know I'm going to feel stupid on this one.. > > I would normally write this in PHP like this: > > for($i=1; i< count($someArray); $i++) > { > print $someArray[i] > } > > essentially,, I want to loop through an array skipping "som

Re: [Tutor] for loop

2008-06-10 Thread bob gailer
Sean Novak wrote: I know I'm going to feel stupid on this one.. I would normally write this in PHP like this: for($i=1; i< count($someArray); $i++) { print $someArray[i] } essentially,, I want to loop through an array skipping "someArray[0]" but in python the for syntax is more like forea

Re: [Tutor] for loop

2008-06-10 Thread Terry Carroll
On Tue, 10 Jun 2008, Sean Novak wrote: > I know I'm going to feel stupid on this one.. > > I would normally write this in PHP like this: > > for($i=1; i< count($someArray); $i++) > { > print $someArray[i] > } > > essentially,, I want to loop through an array skipping "someArray[0]" Like

[Tutor] for loop

2008-06-10 Thread Sean Novak
I know I'm going to feel stupid on this one.. I would normally write this in PHP like this: for($i=1; i< count($someArray); $i++) { print $someArray[i] } essentially,, I want to loop through an array skipping "someArray[0]" but in python the for syntax is more like foreach in PHP.. I'

Re: [Tutor] For loop question

2006-05-10 Thread STREET Gideon (SPARQ)
e typed something incorrectly previously :\ Thanks again Gideon (aka Fatfingers) -Original Message- From: w chun [mailto:[EMAIL PROTECTED] Sent: Thursday, 11 May 2006 1:11 PM To: STREET Gideon (SPARQ) Cc: tutor@python.org Subject: Re: [Tutor] For loop question > Thanks all, appears it is

Re: [Tutor] For loop question

2006-05-10 Thread w chun
> Thanks all, appears it is the newline character which was causing me > grief. For some reason I still have to do a readlines on the open file > at this stage, but I can muck about with that to figure it out. that is surprising... i would be interested in hearing what problems you are encounter

Re: [Tutor] For loop question

2006-05-10 Thread STREET Gideon (SPARQ)
Behalf Of Kent Johnson Sent: Thursday, 11 May 2006 1:03 AM Cc: tutor@python.org Subject: Re: [Tutor] For loop question w chun wrote: > Kent Johnson wrote: >> For short Python scripts I usually allow the runtime to close the file. >> For longer programs and anything written in Jy

Re: [Tutor] For loop question

2006-05-10 Thread w chun
> >> For short Python scripts I usually allow the runtime to close the file. > >> For longer programs and anything written in Jython (which has different > >> garbage collection behaviour) I usually use an explicit close(). > > > > i'm still not comfortable without doing my own explicit close(), es

Re: [Tutor] For loop question

2006-05-10 Thread Kent Johnson
w chun wrote: > Kent Johnson wrote: >> For short Python scripts I usually allow the runtime to close the file. >> For longer programs and anything written in Jython (which has different >> garbage collection behaviour) I usually use an explicit close(). > > i'm still not comfortable without doing

Re: [Tutor] For loop question

2006-05-10 Thread w chun
>> HostFile = open("hosts.txt", 'r') >> for item in [x.strip() for x in HostFile]: >> : >> >>Why is this better when the file is large? It still creates a list with all lines in it. yup, that's why i mention this fact below while giving the genex solution. > > Why not simply: > > > > for

Re: [Tutor] For loop question

2006-05-10 Thread Smith, Jeff
CTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kent Johnson Sent: Wednesday, May 10, 2006 5:52 AM Cc: tutor@python.org Subject: Re: [Tutor] For loop question w chun wrote: > another thing is that if the host file is large, you may wish to > iterate through the file one line at a time with a l

Re: [Tutor] For loop question

2006-05-10 Thread Kent Johnson
Behalf Of Kent Johnson > Sent: Wednesday, May 10, 2006 5:52 AM > Cc: tutor@python.org > Subject: Re: [Tutor] For loop question > > > w chun wrote: >> another thing is that if the host file is large, you may wish to >> iterate through the file one line at a time with

Re: [Tutor] For loop question

2006-05-10 Thread w chun
> Been trying to understand why the following doesn't work: > > HostFile = open("hosts.txt", 'r') > host = HostFile.readlines() > > for item in host: > print "Connecting to device",item > tn = telnetlib.Telnet(item) >: > File "c:\gideon\python24\lib\telnetlib.py", line 225, in ope

[Tutor] For loop question

2006-05-10 Thread STREET Gideon (SPARQ)
Hi all, Been trying to understand why the following doesn't work: HostFile = open("hosts.txt", 'r') host = HostFile.readlines() for item in host: print "Connecting to device",item tn = telnetlib.Telnet(item) ... Do some other stuff here ... I get the following error: Traceback (most r

Re: [Tutor] For loop question

2006-05-10 Thread Kent Johnson
w chun wrote: > another thing is that if the host file is large, you may wish to > iterate through the file one line at a time with a list comprehension > to do the stripping for you: > > HostFile = open("hosts.txt", 'r') > for item in [x.strip() for x in HostFile]: > : Why is this better

Re: [Tutor] For Loop Exercises

2005-05-31 Thread Greg Lindstrom
>I finished the chapter which includes for loop, tuples, indexing and >slicing. Can anyone suggest me 3 exercises to remind of the chapter? A great place to find all sorts of programs to write -- from very easy to complex -- is the programming contest archive on the useless python page (www.usele

[Tutor] For loop exercise

2005-05-30 Thread . ,
I finished the chapter which includes for loop, tuples, indexing and slicing. Can anyone suggest me 3 exercises to remind of the chapter? Thanks. _ Express yourself instantly with MSN Messenger! Download today it's FREE! http://me

Re: [Tutor] for loop

2005-04-19 Thread Alan Gauld
> Well I was reading too fast (as usual) - you wanted to print 'yes' > only if 5 is not in a sub list but you want to look in all the sub > lists and yet print 'yes' only once??? Oops, me too, so in that case > So in long hand lets reverse the logic and make sure we print 'yes' > only once >

Re: [Tutor] for loop

2005-04-19 Thread Alan Gauld
> *Ron A* /Wed Jan 7 18:41:15 EST 2004/ > > I'm experimenting and would like 'yes' to be printed only if 5 is not in > the list, but I want to look in each list. This prints out two yeses. > How do I get it to print just one 'yes'? > > x = [[1,2,3],[2,4,6],[8,4,5,6],[9,8,7]] > > for num in x: >

Re: [Tutor] for loop

2005-04-19 Thread Ewald Ertl
Hi, I've slightly modified the for-Loop containing the "else" and not the if: >>> x = [[1,2,3],[2,4,6],[8,4,5,6],[9,8,7]] >>> for num in x: ... if 5 in num: ... break ... else: ... print "YES" ... >>> second test: >>> x = [[1,2,3],[2,4,6],[8,4,6],[9,8,7]] >>> for num in

Re: [Tutor] for loop

2005-04-18 Thread Lee Cullens
Well I was reading too fast (as usual) - you wanted to print 'yes' only if 5 is not in a sub list but you want to look in all the sub lists and yet print 'yes' only once??? So in long hand lets reverse the logic and make sure we print 'yes' only once >>> yes = 0 >>> for num in x: ... if

Re: [Tutor] for loop

2005-04-18 Thread Lee Cullens
As you probably have already found out the expression >>> print [ e for e in x if 5 in e] will produce [[8, 4, 5, 6]] The problem with your original code is that you are printing 'yes' for each sub list until you encounter a sub list with 5 whereupon you break without printing yes. If you cha

[Tutor] for loop

2005-04-18 Thread Ching-Yi Chan
*Ron A* /Wed Jan 7 18:41:15 EST 2004/ I'm experimenting and would like 'yes' to be printed only if 5 is not in the list, but I want to look in each list. This prints out two yeses. How do I get it to print just one 'yes'? x = [[1,2,3],[2,4,6],[8,4,5,6],[9,8,7]] for num in x: if 5 in num: