Re: Question on for loop

2013-03-05 Thread Bryan Devaney
On Monday, March 4, 2013 4:37:11 PM UTC, Ian wrote: On Mon, Mar 4, 2013 at 7:34 AM, Bryan Devaney bryan.deva...@gmail.com wrote: if character not in lettersGuessed: return True return False assuming a function is being used to pass each letter of the

Question on for loop

2013-03-04 Thread newtopython
Hi all, I'm super new to python, just fyi. In the piece of code below, secretWord is a string and lettersGuessed is a list. I'm trying to find out if ALL the characters of secretWord are included in lettersGuessed, even if there are additional values in the lettersGuessed list that aren't in

Re: Question on for loop

2013-03-04 Thread leo kirotawa
In fact this code is already doing what you want, but if the second character, by example, is not in secrectWord it'll jump out of the for and return. If you want that interact through the all characters and maybe count how many them are in the secrectWord, just take of the return there or do

Re: Question on for loop

2013-03-04 Thread Joel Goldstick
On Mon, Mar 4, 2013 at 7:18 AM, newtopython roshen.set...@gmail.com wrote: Hi all, I'm super new to python, just fyi. Welcome. Next time write a better subject line, and be sure the code you post is actually the code you are running. Provide the results you want and what you get. Provide

Re: Question on for loop

2013-03-04 Thread Dave Angel
On 03/04/2013 07:18 AM, newtopython wrote: Hi all, I'm super new to python, just fyi. Welcome to the Python list. In the piece of code below, secretWord is a string and lettersGuessed is a list. I'm trying to find out if ALL the characters of secretWord are included in lettersGuessed,

Re: Question on for loop

2013-03-04 Thread Bryan Devaney
if character not in lettersGuessed: return True return False assuming a function is being used to pass each letter of the letters guessed inside a loop itself that only continues checking if true is returned, then that could work. It is however more work than is needed.

Re: Question on for loop

2013-03-04 Thread Rick Johnson
On Monday, March 4, 2013 6:18:20 AM UTC-6, newtopython wrote: [Note: Post has be logically re-arranged for your comprehensive pleasures] for character in secretWord: if character not in lettersGuessed: return True return False What this code is doing is only checking the

Re: Question on for loop

2013-03-04 Thread Ian Kelly
On Mon, Mar 4, 2013 at 7:34 AM, Bryan Devaney bryan.deva...@gmail.com wrote: if character not in lettersGuessed: return True return False assuming a function is being used to pass each letter of the letters guessed inside a loop itself that only continues checking if true

Re: Question on for loop

2013-03-04 Thread Ricardo Aráoz
El 04/03/13 09:18, newtopython escribió: Hi all, I'm super new to python, just fyi. In the piece of code below, secretWord is a string and lettersGuessed is a list. I'm trying to find out if ALL the characters of secretWord are included in lettersGuessed, even if there are additional values

Re: Question on for loop

2013-01-15 Thread subhabangalore
On Friday, January 4, 2013 11:18:24 AM UTC+5:30, Steven D'Aprano wrote: On Thu, 03 Jan 2013 12:04:03 -0800, subhabangalore wrote: Dear Group, If I take a list like the following: fruits = ['banana', 'apple', 'mango'] for fruit in fruits: print 'Current fruit :',

Re: Question on for loop

2013-01-04 Thread Alister
On Thu, 03 Jan 2013 12:04:03 -0800, subhabangalore wrote: Dear Group, If I take a list like the following: fruits = ['banana', 'apple', 'mango'] for fruit in fruits: print 'Current fruit :', fruit Now, if I want variables like var1,var2,var3 be assigned to them, we may take,

Question on for loop

2013-01-03 Thread subhabangalore
Dear Group, If I take a list like the following: fruits = ['banana', 'apple', 'mango'] for fruit in fruits: print 'Current fruit :', fruit Now, if I want variables like var1,var2,var3 be assigned to them, we may take, var1=banana, var2=apple, var3=mango but can we do something to

Re: Question on for loop

2013-01-03 Thread MRAB
On 2013-01-03 20:04, subhabangal...@gmail.com wrote: Dear Group, If I take a list like the following: fruits = ['banana', 'apple', 'mango'] for fruit in fruits: print 'Current fruit :', fruit Now, if I want variables like var1,var2,var3 be assigned to them, we may take, var1=banana,

Re: Question on for loop

2013-01-03 Thread Peter Otten
subhabangal...@gmail.com wrote: Dear Group, If I take a list like the following: fruits = ['banana', 'apple', 'mango'] for fruit in fruits: print 'Current fruit :', fruit Now, if I want variables like var1,var2,var3 be assigned to them, we may take, var1=banana, var2=apple,

Re: Question on for loop

2013-01-03 Thread Matt Jones
Yeah, this seems like a bad idea. What exactly are you trying to do here? Maybe using a dictionary is what you want? d = { 'first' : 'banana', 'second' : 'apple', 'third' : 'mango' } for key, value in d.items(): print key, value However I'm still not sure why you'd want to

Re: Question on for loop

2013-01-03 Thread Don Ross
I'm interested to know why you're trying this as well. Is this something that would be helped by creating a class and then dynamically creating instances of that class? Something like... class Fruit: def __init__(self, name): self.name = name for fruit in ['banana', 'apple',

Re: Question on for loop

2013-01-03 Thread alex23
On Jan 4, 6:04 am, subhabangal...@gmail.com wrote: but can we do something to assign the variables dynamically I was thinking of var_series=['var1','var2','var3'] for var in var_series:   for fruit in fruits:        print var,fruits Before trying to do this, write the next bit of code where

Re: Question on for loop

2013-01-03 Thread Steven D'Aprano
On Thu, 03 Jan 2013 12:04:03 -0800, subhabangalore wrote: Dear Group, If I take a list like the following: fruits = ['banana', 'apple', 'mango'] for fruit in fruits: print 'Current fruit :', fruit Now, if I want variables like var1,var2,var3 be assigned to them, we may take,

Question about nested loop

2012-12-31 Thread Isaac Won
Hi all, I am a very novice for Python. Currently, I am trying to read continuous columns repeatedly in the form of array. my code is like below: import numpy as np b = [] c = 4 f = open(text.file, r) while c 10: c = c + 1 for columns in ( raw.strip().split() for raw in f

Re: Question about nested loop

2012-12-31 Thread Gisle Vanem
Isaac Won winef...@gmail.com wrote: while c 10: c = c + 1 for columns in ( raw.strip().split() for raw in f ): b.append(columns[c]) y = np.array(b, float) print c, y I thought that can get the arrays of the columns[5] to [10], but I only could

Re: Question about nested loop

2012-12-31 Thread Hans Mulder
On 31/12/12 11:02:56, Isaac Won wrote: Hi all, I am a very novice for Python. Currently, I am trying to read continuous columns repeatedly in the form of array. my code is like below: import numpy as np b = [] c = 4 f = open(text.file, r) while c 10: c = c + 1

Re: Question about nested loop

2012-12-31 Thread Isaac Won
On Monday, December 31, 2012 5:25:16 AM UTC-6, Gisle Vanem wrote: Isaac Won winef...@gmail.com wrote: while c 10: c = c + 1 for columns in ( raw.strip().split() for raw in f ): b.append(columns[c]) y = np.array(b,

Re: Question about nested loop

2012-12-31 Thread Isaac Won
On Monday, December 31, 2012 6:59:34 AM UTC-6, Hans Mulder wrote: On 31/12/12 11:02:56, Isaac Won wrote: Hi all, I am a very novice for Python. Currently, I am trying to read continuous columns repeatedly in the form of array. my code is like below: import numpy as np

Re: basic python question about for loop

2008-04-12 Thread Jason Stokes
jmDesktop [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] So what is n and x in the first iteration? Sorry. I'm trying. Remember how Python's range operator works. range(n, x) constructs a list that consists of all elements starting with n and up to, but /not including/, x.

Re: basic python question about for loop

2008-04-12 Thread Steve Holden
jmDesktop wrote: [...] So what is n and x in the first iteration? Sorry. I'm trying. Somewhat feebly, if you don't mind my saying so, but don't worry. The usual way to proceed in the face of such ignorance is to insert some form of output that will tell you the answer to your question. So:

basic python question about for loop

2008-04-09 Thread jmDesktop
From the Python.org tutorial: for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ... print n, 'equals', x, '*', n/x ... break ... else: ... # loop fell through without finding a factor ... print n, 'is a prime number' ... 2

Re: basic python question about for loop

2008-04-09 Thread Diez B. Roggisch
jmDesktop schrieb: From the Python.org tutorial: for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ... print n, 'equals', x, '*', n/x ... break ... else: ... # loop fell through without finding a factor ... print

RE: basic python question about for loop

2008-04-09 Thread Reedick, Andrew
-Original Message- From: [EMAIL PROTECTED] [mailto:python- [EMAIL PROTECTED] On Behalf Of jmDesktop Sent: Wednesday, April 09, 2008 4:51 PM To: python-list@python.org Subject: basic python question about for loop From the Python.org tutorial: for n in range(2, 10

Re: basic python question about for loop

2008-04-09 Thread Steve Holden
jmDesktop wrote: From the Python.org tutorial: for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ... print n, 'equals', x, '*', n/x ... break ... else: ... # loop fell through without finding a factor ... print n,

Re: basic python question about for loop

2008-04-09 Thread jmDesktop
On Apr 9, 4:58 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: jmDesktop schrieb: From the Python.org tutorial: for n in range(2, 10): ...     for x in range(2, n): ...         if n % x == 0: ...             print n, 'equals', x, '*', n/x ...             break ...     else:

Re: basic python question about for loop

2008-04-09 Thread jmDesktop
On Apr 9, 4:59 pm, Reedick, Andrew [EMAIL PROTECTED] wrote: -Original Message- From: [EMAIL PROTECTED] [mailto:python- [EMAIL PROTECTED] On Behalf Of jmDesktop Sent: Wednesday, April 09, 2008 4:51 PM To: [EMAIL PROTECTED] Subject: basic python question about for loop From

RE: basic python question about for loop

2008-04-09 Thread Reedick, Andrew
-Original Message- From: [EMAIL PROTECTED] [mailto:python- [EMAIL PROTECTED] On Behalf Of jmDesktop Sent: Wednesday, April 09, 2008 5:04 PM To: python-list@python.org Subject: Re: basic python question about for loop for n in range(2, 10): ...     for x in range(2, n

Re: basic python question about for loop

2008-04-09 Thread Diez B. Roggisch
jmDesktop schrieb: On Apr 9, 4:58 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: jmDesktop schrieb: From the Python.org tutorial: for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ... print n, 'equals', x, '*', n/x ... break ...

Re: basic python question about for loop

2008-04-09 Thread Terry Reedy
|So what is n and x in the first iteration? Sorry. I'm trying. When n == 2, the inner loop executes 0 times (the length of range(2,n)) and then falls thru to the else clause, printing the correct answer. -- http://mail.python.org/mailman/listinfo/python-list

Question about 'for' loop

2007-08-17 Thread Robert Dailey
Hi, I noticed that the 'for' loop can be used inline with a list definition. For example: print [i for i in mylist] My first question is what is the name for this? I couldn't find this usage in the python docs; I only managed to learn about it through code samples on the internet. Secondly,

Re: Question about 'for' loop

2007-08-17 Thread Steve Holden
Robert Dailey wrote: Hi, I noticed that the 'for' loop can be used inline with a list definition. For example: print [i for i in mylist] My first question is what is the name for this? I couldn't find this usage in the python docs; I only managed to learn about it through code

Re: Question about 'for' loop

2007-08-17 Thread Carsten Haese
On Fri, 2007-08-17 at 17:45 -0500, Robert Dailey wrote: [...] Secondly, I'm wondering how I can use this method of a for loop to append strings to strings in a list. For example: mylist = [ Hello , Hello again ] I should be able to do this: print [ i + World for i in mylist ]