Re: Loop with else clause

2019-02-09 Thread DL Neil
Possibly the final contribution:- On 9/02/19 1:30 AM, Adriaan Renting wrote: Wow, you dug deep. =Thank you. It started to 'bug' me, so I really was 'scratching an itch'! My example was the reverse of the "toy example"'s you mention as I find that often code becomes much clearer if you ord

Re: Loop with else clause

2019-02-08 Thread Adriaan Renting
Wow, you dug deep. My example was the reverse of the "toy example"'s you mention as I find that often code becomes much clearer if you order it such that specific cases, sanity checking and exceptions go first, and then the default case at the end. So my general suggestion would be to handle yo

Re: Loop with else clause

2019-02-07 Thread DL Neil
Further to our discussion of how to improve a code review's discovery of the mistaken handling of a for...else... construct:- Yesterday was a national holiday, but today gave some opportunity to research. Way back in 2009 there was spirited discussion over on the Python Ideas list (warning, e

Re: Loop with Else Clause

2019-02-05 Thread Christman, Roger Graydon
-Original Message- From: Python-list On Behalf Of DL Neil Sent: Monday, February 4, 2019 11:29 PM To: 'Python' Subject: Loop with else clause What is the pythonic way to handle the situation where if a condition exists the loop should be executed, but if it does not something else shoul

RE: Loop with else clause

2019-02-05 Thread Avi Gross
The topic is how to deal with a python loop that may not be run if you want something else to happen in that case. Multiple solutions are presented along with this request: > Is there another, more pythonic, approach to conditional (for/while) > loop processing? Has anyone considered looking at

Re: Loop with else clause

2019-02-05 Thread Adriaan Renting
I don't know if it is very Pythonic, but I would do something like if no_oscar_nominees: print ("Sorry ...") else: print_list_of_oscar_nominees() And yes, that for/else construct can be confusing. Adriaan. >>> On 5-2-2019 at 5:29, DL Neil wrote: > What is the pythonic way to handl

RE: Loop with else clause

2019-02-05 Thread David Raymond
org] On Behalf Of Peter Otten Sent: Tuesday, February 05, 2019 3:44 AM To: python-list@python.org Subject: Re: Loop with else clause DL Neil wrote: > What is the pythonic way to handle the situation where if a condition > exists the loop should be executed, but if it does not something

Re: Loop with else clause

2019-02-05 Thread Peter Otten
DL Neil wrote: > What is the pythonic way to handle the situation where if a condition > exists the loop should be executed, but if it does not something else > should be done? > Possible solution: > To make anything more than the trivial case readable, I think I'd put > the list processing into

Re: Loop with else clause

2019-02-05 Thread Ben Finney
DL Neil writes: > Possible solution: > To make anything more than the trivial case readable, I think I'd put > the list processing into one function, and the exception into another > (except that this case is so trivial), ie > > if list: > process_list() #the heading and for-l

Re: Loop with else clause

2019-02-04 Thread DL Neil
On 5/02/19 8:12 PM, Steve wrote: Would it be a hyphythonitical question? Is that one of the new meta-classes in release 3.99, or a perhaps a project to remove the GIL and take advantage of multi-core architectures? As well as embarrassing the poor coder, this question vexed quite a few mind

RE: Loop with else clause

2019-02-04 Thread Steve
Would it be a hyphythonitical question? = Footnote: Zamboni locks up after running into large patch of loose teeth. -Original Message- From: Python-list On Behalf Of DL Neil Sent: Monday, February 4, 2019 11:29 PM To: 'Python' Subject: Loop with else clause What is the

Re: LOOP with fixed final index value

2017-09-30 Thread Stephan Houben
Op 2017-09-27, Robert L. schreef : >> > (defun myloop (initial final increment) >> > (loop for i = initial then (+ i increment) >> > while (< i final) >> > do (print i) >> > finally (let ((i final)) (print i >> > > In Python? myloop = lambda *args: print("{}{}".forma

Re: Loop awareness

2016-02-29 Thread jonas . thornvall
Den måndag 29 februari 2016 kl. 21:32:51 UTC+1 skrev Ian: > On Mon, Feb 29, 2016 at 1:07 PM, wrote: > > This program creates a uniform linktree of x nodes, and it knows when it > > get stuck in a loop generating random values. > > > > Because the networks random generated, only a subset of the p

Re: Loop awareness

2016-02-29 Thread Ian Kelly
On Mon, Feb 29, 2016 at 1:07 PM, wrote: > This program creates a uniform linktree of x nodes, and it knows when it get > stuck in a loop generating random values. > > Because the networks random generated, only a subset of the permutations will > generate a uniform network most get stuck in loo

Re: Loop thru the dictionary with tuples

2014-05-25 Thread Ned Batchelder
On 5/25/14 10:09 PM, Dave Angel wrote: Ned Batchelder Wrote in message: On 5/25/14 8:55 AM, Igor Korot wrote: Hi, ALL, I have a following data structure: my_dict[(var1,var2,var3)] = None my_dict[(var4,var5,var6)] = 'abc' What I'm trying to do is this: for (key,value) in my_dict: #Do s

Re: Loop thru the dictionary with tuples

2014-05-25 Thread Dave Angel
Ned Batchelder Wrote in message: > On 5/25/14 8:55 AM, Igor Korot wrote: >> Hi, ALL, >> I have a following data structure: >> >> my_dict[(var1,var2,var3)] = None >> my_dict[(var4,var5,var6)] = 'abc' >> >> What I'm trying to do is this: >> >> for (key,value) in my_dict: >> #Do some stuff >> >>

Re: Loop thru the dictionary with tuples

2014-05-25 Thread Chris Angelico
On Sun, May 25, 2014 at 11:22 PM, Roy Smith wrote: > Hint: in this case, > it will happen on the assignment line, so, your next step is to print > everything out and see what's going on: > > for thing in my_dict: > print thing > (key, value) = thing Aside: I know that you (Roy) are still

Re: Loop thru the dictionary with tuples

2014-05-25 Thread Ned Batchelder
On 5/25/14 8:55 AM, Igor Korot wrote: Hi, ALL, I have a following data structure: my_dict[(var1,var2,var3)] = None my_dict[(var4,var5,var6)] = 'abc' What I'm trying to do is this: for (key,value) in my_dict: #Do some stuff but I'm getting an error "Too many values to unpack". What am I

Re: Loop thru the dictionary with tuples

2014-05-25 Thread Roy Smith
In article , Igor Korot wrote: > for (key,value) in my_dict: > #Do some stuff > > but I'm getting an error "Too many values to unpack". Several people have already given you the right answer, so I'll just suggest a general debugging technique. Break this down into the smallest possible

Re: Loop thru the dictionary with tuples

2014-05-25 Thread Tim Chase
On 2014-05-25 05:59, Paul Rubin wrote: > Igor Korot writes: > > for (key,value) in my_dict: > > #Do some stuff > > > > but I'm getting an error "Too many values to unpack". > > Use > for (key,value) in mydict.iteritems(): ... You can even use for ((k1,k2,k3), value) in mydict.iterite

Re: Loop thru the dictionary with tuples

2014-05-25 Thread Paul Rubin
Igor Korot writes: > for (key,value) in my_dict: > #Do some stuff > > but I'm getting an error "Too many values to unpack". Use for (key,value) in mydict.iteritems(): ... otherwise you loop through just the keys, whicn in your dictionary happens to be 3-tuples. So you try to unpack a 3

Re: loop

2014-03-24 Thread Chris Angelico
On Mon, Mar 24, 2014 at 9:04 PM, Marko Rauhamaa wrote: > Once in college, we were given assembly programming assignments. The > textbook defined an imagined 18-bit CPU and an instruction set. > > A fellow student was given the task to write a subroutine that > calculates the factorial of the argum

Re: loop

2014-03-24 Thread Marko Rauhamaa
Mark Lawrence : > On 24/03/2014 07:47, Marko Rauhamaa wrote: >> for i in [ 100, 1000, 1, 10, 100, 1000, 1 ]: > > Why the overhead of creating a list when you could use a tuple? :) Once in college, we were given assembly programming assignments. The textbook defined an

Re: loop

2014-03-24 Thread Mark Lawrence
On 24/03/2014 07:47, Marko Rauhamaa wrote: Chris Angelico : On Mon, Mar 24, 2014 at 11:35 AM, wrote: I'm trying to create a for loop that starts at 100 and goes to 10Mllion. That sounds like a logarithmic scale. How about: for i in [ 100, 1000, 1, 10, 100, 1000, 100

Re: loop

2014-03-24 Thread Marko Rauhamaa
Chris Angelico : > On Mon, Mar 24, 2014 at 11:35 AM, wrote: >> I'm trying to create a for loop that starts at 100 and goes to 10Mllion. > > That sounds like a logarithmic scale. How about: for i in [ 100, 1000, 1, 10, 100, 1000, 1 ]: ... Marko -- https://

Re: loop

2014-03-23 Thread Mark H Harris
On 3/23/14 7:59 PM, anton wrote: for i in (10**p for p in range(3, 8)): print(i) Never do their home-work for them; but, in this case, what the heck. :) -- https://mail.python.org/mailman/listinfo/python-list

Re: loop

2014-03-23 Thread Ben Finney
pabloerugg...@gmail.com writes: > I'm trying to create a for loop that starts at 100 and goes to > 10Mllion. The increments are like this: 100, 1000, 1, . > Basicaly adding a zero each iteration. I'm having problems trying to > do it. Can somebody help me Welcome. What have you tried so

Re: loop

2014-03-23 Thread anton
for i in (10**p for p in range(3, 8)): print(i) -- https://mail.python.org/mailman/listinfo/python-list

Re: loop

2014-03-23 Thread pabloeruggeri
Thanks!! -- https://mail.python.org/mailman/listinfo/python-list

Re: loop

2014-03-23 Thread Mark Lawrence
On 24/03/2014 00:35, pabloerugg...@gmail.com wrote: Hello, I'm trying to create a for loop that starts at 100 and goes to 10Mllion. The increments are like this: 100, 1000, 1, . Basicaly adding a zero each iteration. I'm having problems trying to do it. Can somebody help me Start by

Re: loop

2014-03-23 Thread Chris Angelico
On Mon, Mar 24, 2014 at 11:35 AM, wrote: > Hello, > > I'm trying to create a for loop that starts at 100 and goes to 10Mllion. The > increments are like this: 100, 1000, 1, . Basicaly adding a zero each > iteration. I'm having problems trying to do it. Can somebody help me > That sound

Re: loop

2014-03-23 Thread MRAB
On 2014-03-24 00:35, pabloerugg...@gmail.com wrote: Hello, I'm trying to create a for loop that starts at 100 and goes to 10Mllion. The increments are like this: 100, 1000, 1, . Basicaly adding a zero each iteration. I'm having problems trying to do it. Can somebody help me Probably be

Re: Loop Question

2013-06-25 Thread Dave Angel
On 06/24/2013 08:20 AM, Lutz Horn wrote: Hi, Am 24.06.2013 14:12 schrieb christheco...@gmail.com: username=raw_input("Please enter your username: ") password=raw_input("Please enter your password: ") if username == "john doe" and password == "fopwpo": print "Login Successful" else: pr

Re: Loop Question

2013-06-25 Thread Lutz Horn
Hi, Am 24.06.2013 14:12 schrieb christheco...@gmail.com: username=raw_input("Please enter your username: ") password=raw_input("Please enter your password: ") if username == "john doe" and password == "fopwpo": print "Login Successful" else: print "Please try again" while not usernam

Re: Loop Question

2013-06-24 Thread Dave Angel
On 06/24/2013 03:00 PM, John Gordon wrote: In =?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?= writes: while True: username = raw_input("Please enter your username: ") password = raw_input("Please enter your password: ") if username == "john doe" and password == "fopwpo":

Re: Loop Question

2013-06-24 Thread John Gordon
In =?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?= writes: > > while True: > > username = raw_input("Please enter your username: ") > > password = raw_input("Please enter your password: ") > > > > if username == "john doe" and password == "fopwpo": > > print "Login Suc

Re: Loop Question

2013-06-24 Thread Chris “Kwpolska” Warrick
On Mon, Jun 24, 2013 at 8:42 PM, John Gordon wrote: > In > christheco...@gmail.com writes: > >> On Sunday, June 23, 2013 6:18:35 PM UTC-5, christ...@gmail.com wrote: >> > How do I bring users back to beginning of user/password question once they >> > >> > fail it? thx > >> Can't seem to get this

Re: Loop Question

2013-06-24 Thread John Gordon
In christheco...@gmail.com writes: > On Sunday, June 23, 2013 6:18:35 PM UTC-5, christ...@gmail.com wrote: > > How do I bring users back to beginning of user/password question once they > > > > fail it? thx > Can't seem to get this to cooperate...where does the while statement belong? while T

Re: Loop Question

2013-06-24 Thread christhecomic
On Sunday, June 23, 2013 6:18:35 PM UTC-5, christ...@gmail.com wrote: > How do I bring users back to beginning of user/password question once they > > fail it? thx Can't seem to get this to cooperate...where does the while statement belong? -- http://mail.python.org/mailman/listinfo/python-list

Re: Loop Question

2013-06-24 Thread rusi
On Monday, June 24, 2013 5:42:51 PM UTC+5:30, christ...@gmail.com wrote: > Here is my code...I'm using 2.7.5 > > > username=raw_input("Please enter your username: ") > password=raw_input("Please enter your password: ") > if username == "john doe" and password == "fopwpo": > print "Login Succ

Re: Loop Question

2013-06-24 Thread christhecomic
Here is my code...I'm using 2.7.5 username=raw_input("Please enter your username: ") password=raw_input("Please enter your password: ") if username == "john doe" and password == "fopwpo": print "Login Successful" else: print "Please try again" -- http://mail.python.org/mailman/listinfo/

Re: Loop Question

2013-06-23 Thread christhecomic
I'm using 2.7 -- http://mail.python.org/mailman/listinfo/python-list

Re: Loop Question

2013-06-23 Thread Steven D'Aprano
On Sun, 23 Jun 2013 16:18:35 -0700, christhecomic wrote: > How do I bring users back to beginning of user/password question once > they fail it? thx Write a loop. If they don't fail (i.e. they get the password correct), then break out of the loop. -- Steven -- http://mail.python.org/mailman/

Re: Loop Question

2013-06-23 Thread rurpy
On 06/23/2013 05:18 PM, christheco...@gmail.com wrote: > How do I bring users back to beginning of user/password question once they > fail it? thx This is not a very good question. There is no context so we cannot tell if you are talking about a command line program that prompts for a username

Re: Loop through a dict changing keys

2011-10-17 Thread Gnarlodious
Steven: Thanks for those tips, I've implemented all of them. Also only allowing whitelisted variable names. Feeling much more confident. -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Re: Loop through a dict changing keys

2011-10-17 Thread Steven D'Aprano
On Sun, 16 Oct 2011 17:41:55 -0700, Gnarlodious wrote: > On Oct 16, 5:25 pm, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: > >> How do you sanitize user input? > Thanks for your concern. This is what I now have, which merely expands > each value into its usable type (unquotes them): >

Re: Loop through a dict changing keys

2011-10-17 Thread Gnarlodious
On Oct 16, 5:25 pm, Steven D'Aprano wrote: > How do you sanitize user input? Thanks for your concern. This is what I now have, which merely expands each value into its usable type (unquotes them): # filter each value try: var=int(var) except ValueError: if var in ('False', 'True'): v

Re: Loop through a dict changing keys

2011-10-17 Thread PoD
On Sun, 16 Oct 2011 00:18:40 -0700, Jon Clements wrote: > On Oct 16, 12:53 am, PoD wrote: >> On Sat, 15 Oct 2011 11:00:17 -0700, Gnarlodious wrote: >> > What is the best way (Python 3) to loop through dict keys, examine >> > the string, change them if needed, and save the changes to the same >> >

Re: Loop through a dict changing keys

2011-10-17 Thread Steven D'Aprano
On Sun, 16 Oct 2011 11:20:49 -0700, Gnarlodious wrote: > On Oct 15, 5:53 pm, PoD wrote: > >> data = { >>     'Mobile': 'string', >>     'context': '', >>     'order': '7', >>     'time': 'True'} >> types={'Mobile':str,'context':str,'order':int,'time':bool} >> >> for k,v in data.items(): >>     d

Re: Loop through a dict changing keys

2011-10-17 Thread Ian Kelly
On Mon, Oct 17, 2011 at 10:21 AM, 8 dihedral wrote: > Uh, sounds reasonable, if one loops over an index variable  that could be > altered during the loop execution then the loop may not end as expected. >From the docs: "Iterating views while adding or deleting entries in the dictionary may

Re: Loop through a dict changing keys

2011-10-17 Thread 88888 dihedral
Uh, sounds reasonable, if one loops over an index variable that could be altered during the loop execution then the loop may not end as expected. -- http://mail.python.org/mailman/listinfo/python-list

Re: Loop through a dict changing keys

2011-10-17 Thread Chris Angelico
On Mon, Oct 17, 2011 at 5:20 AM, Gnarlodious wrote: > On Oct 15, 5:53 pm, PoD wrote: > >> types={'Mobile':str,'context':str,'order':int,'time':bool} >> >> for k,v in data.items(): >>     data[k] = types[k](v) > > Thanks for the tip, I didn't know you could do that. I ended up > filtering the valu

Re: Loop through a dict changing keys

2011-10-17 Thread Gnarlodious
On Oct 15, 5:53 pm, PoD wrote: > data = { >     'Mobile': 'string', >     'context': '', >     'order': '7', >     'time': 'True'} > types={'Mobile':str,'context':str,'order':int,'time':bool} > > for k,v in data.items(): >     data[k] = types[k](v) Thanks for the tip, I didn't know you could do

Re: Loop through a dict changing keys

2011-10-16 Thread Jon Clements
On Oct 16, 12:53 am, PoD wrote: > On Sat, 15 Oct 2011 11:00:17 -0700, Gnarlodious wrote: > > What is the best way (Python 3) to loop through dict keys, examine the > > string, change them if needed, and save the changes to the same dict? > > > So for input like this: > > {'Mobile': 'string', 'cont

Re: Loop through a dict changing keys

2011-10-15 Thread PoD
On Sat, 15 Oct 2011 11:00:17 -0700, Gnarlodious wrote: > What is the best way (Python 3) to loop through dict keys, examine the > string, change them if needed, and save the changes to the same dict? > > So for input like this: > {'Mobile': 'string', 'context': '', 'order': '7', > 'time': 'True'}

Re: Loop through a dict changing keys

2011-10-15 Thread 88888 dihedral
Is there an FAQ available here? Please check the PYTHON official site and the active state PYTHON examples first, also check the PLEAC comparisons of a lot programming languages first! - Nothing is more thrilling to o

Re: Loop through a dict changing keys

2011-10-15 Thread Alexander Kapps
On 15.10.2011 20:00, Gnarlodious wrote: What is the best way (Python 3) to loop through dict keys, examine the string, change them if needed, and save the changes to the same dict? So for input like this: {'Mobile': 'string', 'context': '', 'order': '7', 'time': 'True'} I want to booleanize 'Tr

Re: Loop through a dict changing keys

2011-10-15 Thread MRAB
On 15/10/2011 19:00, Gnarlodious wrote: What is the best way (Python 3) to loop through dict keys, examine the string, change them if needed, and save the changes to the same dict? So for input like this: {'Mobile': 'string', 'context': '', 'order': '7', 'time': 'True'} I want to booleanize 'Tr

Re: loop over list and process into groups

2010-03-05 Thread mk
lbolla wrote: It looks like Perl ;-) A positive proof that you can write perl code in Python. I, for instance, have had my brain warped by C and tend to write C-like code in Python. That's only half a joke, sadly. I'm trying to change my habits but it's hard. Regards, mk -- http://mail.p

Re: loop over list and process into groups

2010-03-05 Thread mk
nn wrote: Oh my! You could have at least used some "if else" to make it a little bit easier on the eyes :-) That's my entry into """'Obfuscated' "Python" '"''code''"' '"contest"'""" and I'm proud of it. ;-) Regards, mk -- http://mail.python.org/mailman/listinfo/python-list

Re: loop over list and process into groups

2010-03-05 Thread lbolla
On Mar 5, 1:26 pm, mk wrote: > Sneaky Wombat wrote: > > [ 'VLAN4065', > >  'Interface', > >  'Gi9/6', > >  'Po2', > >  'Po3', > >  'Po306', > >  'VLAN4068', > >  'Interface', > >  'Gi9/6', > >  'VLAN4069', > >  'Interface', > >  'Gi9/6',] > > Hey, I just invented a cute ;-) two-liner using list co

Re: loop over list and process into groups

2010-03-05 Thread nn
mk wrote: > Sneaky Wombat wrote: > > [ 'VLAN4065', > > 'Interface', > > 'Gi9/6', > > 'Po2', > > 'Po3', > > 'Po306', > > 'VLAN4068', > > 'Interface', > > 'Gi9/6', > > 'VLAN4069', > > 'Interface', > > 'Gi9/6',] > > Hey, I just invented a cute ;-) two-liner using list comprehensions: > >

Re: loop over list and process into groups

2010-03-05 Thread mk
Sneaky Wombat wrote: [ 'VLAN4065', 'Interface', 'Gi9/6', 'Po2', 'Po3', 'Po306', 'VLAN4068', 'Interface', 'Gi9/6', 'VLAN4069', 'Interface', 'Gi9/6',] Hey, I just invented a cute ;-) two-liner using list comprehensions: # alist = list above tmp, dk = [], {} [(x.startswith('VLAN') and

Re: loop over list and process into groups

2010-03-05 Thread Paul Rubin
lbolla writes: > for k, g in groupby(clean_up(data) , key=lambda s: s.startswith('VLAN')): > if k: > key = list(g)[0].replace('VLAN','') This is the nicest solution, I think. Mine was more cumbersome. -- http://mail.python.org/mailman/listinfo/python-list

Re: loop over list and process into groups

2010-03-04 Thread Chris Colbert
Man, deja-vu, I could have sworn I read this thread months ago... On Thu, Mar 4, 2010 at 2:18 PM, nn wrote: > > > lbolla wrote: > > On Mar 4, 3:57 pm, Sneaky Wombat wrote: > > > [ {'vlan_or_intf': 'VLAN2021'}, > > > {'vlan_or_intf': 'Interface'}, > > > {'vlan_or_intf': 'Po1'}, > > > {'vlan_o

Re: loop over list and process into groups

2010-03-04 Thread nn
lbolla wrote: > On Mar 4, 3:57 pm, Sneaky Wombat wrote: > > [ {'vlan_or_intf': 'VLAN2021'}, > >  {'vlan_or_intf': 'Interface'}, > >  {'vlan_or_intf': 'Po1'}, > >  {'vlan_or_intf': 'Po306'}, > >  {'vlan_or_intf': 'VLAN2022'}, > >  {'vlan_or_intf': 'Interface'}, > >  {'vlan_or_intf': 'Gi7/33'}, >

Re: loop over list and process into groups

2010-03-04 Thread lbolla
On Mar 4, 3:57 pm, Sneaky Wombat wrote: > [ {'vlan_or_intf': 'VLAN2021'}, >  {'vlan_or_intf': 'Interface'}, >  {'vlan_or_intf': 'Po1'}, >  {'vlan_or_intf': 'Po306'}, >  {'vlan_or_intf': 'VLAN2022'}, >  {'vlan_or_intf': 'Interface'}, >  {'vlan_or_intf': 'Gi7/33'}, >  {'vlan_or_intf': 'Po1'}, >  {'v

Re: loop over list and process into groups

2010-03-04 Thread Sneaky Wombat
On Mar 4, 10:55 am, mk wrote: > Sneaky Wombat wrote: > > I was going to write a def to loop through and look for certain pre- > > compiled regexs, and then put them in a new dictionary and append to a > > list, > > regexes are overkill in this case I think. > > > [ 'VLAN4065', > >  'Interface', >

Re: loop over list and process into groups

2010-03-04 Thread mk
Sneaky Wombat wrote: I was going to write a def to loop through and look for certain pre- compiled regexs, and then put them in a new dictionary and append to a list, regexes are overkill in this case I think. [ 'VLAN4065', 'Interface', 'Gi9/6', 'Po2', 'Po3', 'Po306', 'VLAN4068', 'Int

Re: loop through each line in a text file

2010-03-01 Thread qtrimble
On Feb 26, 6:19 pm, ru...@yahoo.com wrote: > On Feb 26, 2:21 pm, qtrimble wrote: > > > > > On Feb 26, 4:14 pm, OdarR wrote: > > > > > > below is just a sample.  There are well over 500,000 lines that need > > > > processed. > > > > > wer1999001 > > > >       31.2234      82.2367 > > > >       37

Re: loop through each line in a text file

2010-02-26 Thread alex goretoy
I smell homework -- http://mail.python.org/mailman/listinfo/python-list

Re: loop through each line in a text file

2010-02-26 Thread rurpy
On Feb 26, 2:21 pm, qtrimble wrote: > On Feb 26, 4:14 pm, OdarR wrote: > > > > below is just a sample.  There are well over 500,000 lines that need > > > processed. > > > > wer1999001 > > >       31.2234      82.2367 > > >       37.9535      82.3456 > > > wer1999002 > > >       31.2234      82.2

Re: loop through each line in a text file

2010-02-26 Thread John Posner
On 2/26/2010 4:21 PM, qtrimble wrote: fileIN = open(r"C:\testing.txt", "r") for line in fileIN: year = line[3:7] day = line[7:10] print year, day This is good since i can get the year and day of year into a variable but I haven't gotten any further. That's an excellent start.

Re: loop through each line in a text file

2010-02-26 Thread qtrimble
On Feb 26, 4:14 pm, OdarR wrote: > On 26 fév, 22:08, qtrimble wrote: > > > > > I'm a python newbie but I do have some basic scripting experience.  I > > need to take the line starting with "wer" and extract the year and day > > of year from that string.  I want to be able to add the year and day

Re: loop through each line in a text file

2010-02-26 Thread OdarR
On 26 fév, 22:08, qtrimble wrote: > I'm a python newbie but I do have some basic scripting experience.  I > need to take the line starting with "wer" and extract the year and day > of year from that string.  I want to be able to add the year and day > of year from the last line having "wer*" to th

Re: loop through each line in a text file

2010-02-26 Thread Alf P. Steinbach
* qtrimble: I'm a python newbie but I do have some basic scripting experience. I need to take the line starting with "wer" and extract the year and day of year from that string. I want to be able to add the year and day of year from the last line having "wer*" to the lines occurring in between

Re: Loop problem while generating a new value with random.randint()

2010-02-15 Thread Paulo Repreza
Thanks for the help! Using while True helps alot! Paulo Repreza -- http://mail.python.org/mailman/listinfo/python-list

Re: Loop problem while generating a new value with random.randint()

2010-02-15 Thread Steve Holden
Paulo Repreza wrote: > Greetings, > > I'm having problems with a little script that I'm trying to finish, I > don't know if I'm in the right track but I know somebody is going to > help me. > > The script: > > # Import modules random for function randint > > import random > > # Generating a co

Re: Loop problem while generating a new value with random.randint()

2010-02-15 Thread Arnaud Delobelle
Jean-Michel Pichavant writes: > Paulo Repreza wrote: >> Greetings, >> >> I'm having problems with a little script that I'm trying to finish, >> I don't know if I'm in the right track but I know somebody is going >> to help me. >> >> The script: >> >> # Import modules random for function randint >

Re: Loop problem while generating a new value with random.randint()

2010-02-15 Thread Bruno Desthuilliers
Jean-Michel Pichavant a écrit : Paulo Repreza wrote: Greetings, I'm having problems with a little script that I'm trying to finish, I don't know if I'm in the right track but I know somebody is going to help me. (snip - problem already addressed by Jean-Michel...) while var != ranum:

Re: Loop problem while generating a new value with random.randint()

2010-02-15 Thread Jean-Michel Pichavant
Paulo Repreza wrote: Greetings, I'm having problems with a little script that I'm trying to finish, I don't know if I'm in the right track but I know somebody is going to help me. The script: # Import modules random for function randint import random # Generating a constant. var = 65 #

Re: loop? maybe?

2009-04-10 Thread Mike Driscoll
On Apr 10, 7:42 am, heidi taynton wrote: > Hey guys, > > Sorry for being such a noob with this stuff and the language is hard for me > to read through with the online manuals...  i can do math speak, and science > speak... not so much programming/code speak... so when you say pickle... i > thin

Re: loop performance in global namespace (python-2.6.1)

2009-03-12 Thread Lie Ryan
John Machin wrote: On Mar 13, 2:41 am, spir wrote: Le Thu, 12 Mar 2009 11:13:33 -0400, Kent Johnson s'exprima ainsi: Because local name lookup is faster than global name lookup. Local variables are stored in an array in the stack frame and accessed by index. Global names are stored in a dict

Re: loop performance in global namespace (python-2.6.1)

2009-03-12 Thread John Machin
On Mar 13, 2:41 am, spir wrote: > Le Thu, 12 Mar 2009 11:13:33 -0400, > Kent Johnson s'exprima ainsi: > > > Because local name lookup is faster than global name lookup. Local > > variables are stored in an array in the stack frame and accessed by > > index. Global names are stored in a dict and a

Re: loop performance in global namespace (python-2.6.1)

2009-03-12 Thread Scott David Daniels
Poor Yorick wrote: In the following snippet, the loop in the global namespace takes twice as long as the loop in the function namespace. Why? Locals are known to have no outside interaction, and so are not looked up by name. your code could have a thread that did, global counter

Re: loop performance in global namespace (python-2.6.1)

2009-03-12 Thread Duncan Booth
Poor Yorick wrote: > In the following snippet, the loop in the global namespace takes twice > as long as the loop in the function namespace. Why? > Accessing global variables is generally slower than accessing local variables. Locals are effectively stored in a vector so the bytecode can go s

Re: Loop in a loop?

2008-01-18 Thread Sacred Heart
On Jan 17, 7:39 pm, Paul Rubin wrote: > Sacred Heart <[EMAIL PROTECTED]> writes: > > array1 = ['one','two','three','four'] > > array2 = ['a','b','c','d'] > > > I want to loop through array1 and add elements from array2 at the end, > > so it looks like this: > > > one a >

Re: Loop in a loop?

2008-01-18 Thread cokofreedom
> Hehe.. I remember seeing a similar one for Java and "Hello world" > using more and more elaborate abstractions and design patterns but I > can't find the link. > > George This is not linked to Java but deals with Hello World http://www.ariel.com.au/jokes/The_Evolution_of_a_Programmer.html -- h

Re: Loop in a loop?

2008-01-18 Thread Bruno Desthuilliers
Paul Rubin a écrit : > George Sakkis <[EMAIL PROTECTED]> writes: >> And if the iterables don't necessarily support len(), here's a more >> general solution: > > Not trying to pick on you personally but there's this disease > when a newbie comes with a basically simple question (in this case, > how

Re: Loop in a loop?

2008-01-18 Thread Bruno Desthuilliers
Roel Schroeven a écrit : > Sacred Heart schreef: >> On Jan 17, 1:35 pm, [EMAIL PROTECTED] wrote: >>> for i in zip(array1, array2): >>> print i >>> >>> Although I take it you meant four d, the issue with this method is >>> that once you hit the end of one array the rest of the other one is >>> i

Re: Loop in a loop?

2008-01-17 Thread Arnaud Delobelle
On Jan 17, 11:59 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > Instead of counting the exceptions, we can limit the padding iterables > by using an iterator that returns len(iterables) - 1 padding > generators, use a sort of lazy chain, and then just izip. > > from itertools import izip, repeat > >

Re: Loop in a loop?

2008-01-17 Thread George Sakkis
On Jan 17, 7:13 pm, Paul Rubin wrote: > George Sakkis <[EMAIL PROTECTED]> writes: > > And if the iterables don't necessarily support len(), here's a more > > general solution: > > Not trying to pick on you personally but there's this disease > when a newbie comes with a

Re: Loop in a loop?

2008-01-17 Thread Paul Rubin
George Sakkis <[EMAIL PROTECTED]> writes: > And if the iterables don't necessarily support len(), here's a more > general solution: Not trying to pick on you personally but there's this disease when a newbie comes with a basically simple question (in this case, how to solve the problem with ordina

Re: Loop in a loop?

2008-01-17 Thread Paul Hankin
On Jan 17, 7:02 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > On Jan 17, 12:25 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > > > > > On Jan 17, 4:38 pm, Bruno Desthuilliers > > [EMAIL PROTECTED]> wrote: > > > Now there are very certainly smart solutions using itertools, but the > > > one I cooked

Re: Loop in a loop?

2008-01-17 Thread George Sakkis
On Jan 17, 12:25 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > On Jan 17, 4:38 pm, Bruno Desthuilliers > [EMAIL PROTECTED]> wrote: > > Now there are very certainly smart solutions using itertools, but the > > one I cooked is way too ugly so I'll leave this to itertools masters !-) > > Here's my ef

Re: Loop in a loop?

2008-01-17 Thread Paul Rubin
Sacred Heart <[EMAIL PROTECTED]> writes: > array1 = ['one','two','three','four'] > array2 = ['a','b','c','d'] > > I want to loop through array1 and add elements from array2 at the end, > so it looks like this: > > one a > two b > three c > four c The "functional" style is to use the zip function

Re: Loop in a loop?

2008-01-17 Thread Roel Schroeven
Sacred Heart schreef: > On Jan 17, 1:35 pm, [EMAIL PROTECTED] wrote: >> for i in zip(array1, array2): >> print i >> >> Although I take it you meant four d, the issue with this method is >> that once you hit the end of one array the rest of the other one is >> ignored. > > Yes, small typo there

Re: Loop in a loop?

2008-01-17 Thread Paul Hankin
On Jan 17, 4:38 pm, Bruno Desthuilliers wrote: > Now there are very certainly smart solutions using itertools, but the > one I cooked is way too ugly so I'll leave this to itertools masters !-) Here's my effort: from itertools import izip, islice, chain, repeat def padzip(*xs, **kw): pad =

Re: Loop in a loop?

2008-01-17 Thread sturlamolden
On 17 Jan, 14:38, Sacred Heart <[EMAIL PROTECTED]> wrote: > Okey, so if my array1 is has 4 elements, and array2 has 6, it won't > loop trough the last 2 in array2? How do I make it do that? In that case your problem is the data. You'll either have to truncate one array and/or pad the other. Or i

Re: Loop in a loop?

2008-01-17 Thread sturlamolden
On 17 Jan, 13:21, Sacred Heart <[EMAIL PROTECTED]> wrote: > A push in the right direction, anyone? for number,letter in zip(array1,array2): print "%s %s" % (number,letter) -- http://mail.python.org/mailman/listinfo/python-list

  1   2   3   >