Re: [Tutor] Looping through Dictionaries

2017-05-23 Thread Mats Wichmann
On 05/23/2017 11:38 AM, Rafael Knuth wrote: > I wrote a function (shopping list) which calculates the total price of > the purchase (quantity * price) as well as the stock change (stock - > quantity). I know the latter is imperfect (my function does not take > into account if items are out of stock

Re: [Tutor] Looping through Dictionaries

2017-05-23 Thread Alan Gauld via Tutor
On 23/05/17 18:38, Rafael Knuth wrote: > Now, I want to print the item next to the stock update, and I am > receiving an error message. I couldn't figure out how to fix that: So show us the error message, all of it. I can't begin to guess what it might be. UI also don't understand what "print th

Re: [Tutor] looping - beginner question

2017-03-02 Thread leam hall
On Thu, Mar 2, 2017 at 8:42 AM, Rafael Knuth wrote: > I wrote a program that is supposed to take orders from customers in a bar. > If the desired drink is available, the customer will be served. If > not, he will be informed that the drink is not available. This is what > I wrote: > > bar = ["bee

Re: [Tutor] looping - beginner question

2017-03-02 Thread Mats Wichmann
On 03/02/2017 08:06 AM, Alan Gauld via Tutor wrote: > On 02/03/17 13:42, Rafael Knuth wrote: > >> bar = ["beer", "coke", "wine"] >> >> customer_order = input("What would you like to drink, dear guest? ") >> >> for drink in bar: >> if customer_order != drink: >> print ("Sorry, we don't

Re: [Tutor] looping - beginner question

2017-03-02 Thread Alan Gauld via Tutor
On 02/03/17 13:42, Rafael Knuth wrote: > bar = ["beer", "coke", "wine"] > > customer_order = input("What would you like to drink, dear guest? ") > > for drink in bar: > if customer_order != drink: > print ("Sorry, we don't serve %s." % customer_order) > else: > print ("Su

Re: [Tutor] looping generator

2016-01-07 Thread Alan Gauld
On 07/01/16 18:31, richard kappler wrote: > Alan, have you ever actually been guilty of 'missing something'? :-) Actually quite often. Usually when its late at night(tired) or early morning(no coffee) or I'm rushing to go someplace. But it happens quite a lot, Usually Steven or Peter or someone w

Re: [Tutor] looping generator

2016-01-07 Thread Martin A. Brown
Hi there Richard, >I have a stream of incoming xml data. I can receive the data, parse >the data, etc, so long as I don't get fancy and I have a miniscule >delay in between each message. If I get rid of the time delay, >which I need to, I need the script to continuously process the >incoming

Re: [Tutor] Looping over histogram plots

2012-06-27 Thread Mark Lawrence
On 27/06/2012 08:47, Alan Gauld wrote: On 27/06/12 00:32, Elaina Ann Hyde wrote: Thanks for the comment, the set type is no problem for me, this is just a variable that I call set... and it works great for my purposes, It may work just now but if you ever decide you need to use a Python set y

Re: [Tutor] Looping over histogram plots

2012-06-27 Thread Steven D'Aprano
On Wed, Jun 27, 2012 at 08:47:08AM +0100, Alan Gauld wrote: > On 27/06/12 00:32, Elaina Ann Hyde wrote: > > > Thanks for the comment, the set type is no problem for me, this is > >just a variable that I call set... and it works great for my purposes, > > It may work just now but if you ever d

Re: [Tutor] Looping over histogram plots

2012-06-27 Thread Alan Gauld
On 27/06/12 00:32, Elaina Ann Hyde wrote: Thanks for the comment, the set type is no problem for me, this is just a variable that I call set... and it works great for my purposes, It may work just now but if you ever decide you need to use a Python set you will be unable to because you h

Re: [Tutor] Looping over histogram plots

2012-06-26 Thread Elaina Ann Hyde
Yay Python: The solution was a syntax one, if anyone else ever feels like massively multi-plotting histograms, here is the working code: #-- fig, axes = plt.subplots(nrows=5, ncols=6, figsize=(12,6)) index=0 for b in axes: for ax in b: inde

Re: [Tutor] Looping over histogram plots

2012-06-26 Thread Elaina Ann Hyde
Dear Don, Thanks for the comment, the set type is no problem for me, this is just a variable that I call set... and it works great for my purposes, I do suspect it is something in the way that matplotlib/pyplot deals with histograms, but I have not so far been able to find the right syntax. No

Re: [Tutor] Looping over histogram plots

2012-06-26 Thread Don Jennings
> Message: 1 > Date: Tue, 26 Jun 2012 18:40:50 +1000 > From: Elaina Ann Hyde > To: tutor@python.org > Subject: [Tutor] Looping over histogram plots >set=(dat['a'+str(index)] == 1.00) You should not override the builtin set() type [1] as you've done here by assigning it. > #write the

Re: [Tutor] Looping

2009-04-20 Thread Paul McGuire
> > xrange was a kludge to improve on range's memory efficiency > but it is a horrible name that obscures the code. > > Also it does not exist in v3 so if you use it you will need to change > the code for v3. It is as well to be as consistent with v3 as possible > IMHO > > Alan G I have felt th

Re: [Tutor] Looping

2009-04-20 Thread Alan Gauld
"Matt" wrote As an aside, why use range rather than xrange? I was under the impression that xrange is a generator and therefore more memory efficient. xrange was a kludge to improve on range's memory efficiency but it is a horrible name that obscures the code. Also it does not exist in v3 s

Re: [Tutor] Looping

2009-04-20 Thread W W
On Mon, Apr 20, 2009 at 12:34 PM, Matt > wrote: > Thank you. Func is in fact a call to an external non-python program. =] > Therefore, the loop must actually be mindlessly done. My question, however, > has been answered. > As an aside, why use range rather than xrange? I was under the impression

Re: [Tutor] Looping

2009-04-20 Thread Matt
Thank you. Func is in fact a call to an external non-python program. =] Therefore, the loop must actually be mindlessly done. My question, however, has been answered. As an aside, why use range rather than xrange? I was under the impression that xrange is a generator and therefore more memory effic

Re: [Tutor] Looping

2009-04-20 Thread Alan Gauld
"Matt" wrote Let's say I want to run func 10 times Is there a more pythonic way to do it than this: for i in xrange(10): func() Yes, use range() rather than xrange :-) But more seriously, as others have pointed out, if func() is well written then calling it ten times will have no e

Re: [Tutor] Looping

2009-04-20 Thread spir
Le Mon, 20 Apr 2009 17:26:30 +0200, "A.T.Hofkamp" s'exprima ainsi: > Matt wrote: > > Hey everyone, > > > > First post to this list. I hope I'm doing it right. > > > > Let's say I want to run func 10 times Is there a more pythonic way to do > > it than this: for i in xrange(10): > > func() > >

Re: [Tutor] Looping

2009-04-20 Thread A.T.Hofkamp
Matt wrote: Hey everyone, First post to this list. I hope I'm doing it right. Let's say I want to run func 10 times Is there a more pythonic way to do it than this: for i in xrange(10): func() no, that looks fine for your requirement. What may be a bit weird here is the requirement to run

Re: [Tutor] Looping

2009-04-20 Thread W W
On Mon, Apr 20, 2009 at 8:48 AM, Matt > wrote: > Hey everyone, > > First post to this list. I hope I'm doing it right. > > Let's say I want to run func 10 times Is there a more pythonic way to do it > than this: > for i in xrange(10): > func() AFAIK that's the most pythonic way to do it... and

Re: [Tutor] Looping, and Win32com.client

2008-12-19 Thread Andreas Kostyrka
Am Fri, 19 Dec 2008 15:57:49 + schrieb Tim Golden : > Eduardo Vieira wrote: > > Hello, this is my first post in this list and I'm not a programmer, > > but am enjoying learning python. > > I'm trying to make a script to add worksheets to excel files: > > I managed to implement this code: > >

Re: [Tutor] Looping, and Win32com.client

2008-12-19 Thread Tim Golden
Tim Golden wrote: Eduardo Vieira wrote: Hello, this is my first post in this list and I'm not a programmer, but am enjoying learning python. I'm trying to make a script to add worksheets to excel files: I managed to implement this code: import os folder = 'C:\\Personal\\oldxlsformat\\' from win

Re: [Tutor] Looping, and Win32com.client

2008-12-19 Thread Eduardo Vieira
Thank you, now it worked! I made these changes to my code: for ficheiro in os.listdir(folder): file = os.path.join(folder, ficheiro) #added this if ficheiro.endswith('.xls'): wb = xl.Workbooks.Open(file, 2) # changed this On Fri, Dec 19, 2008 at 8:57 AM, Tim Golden wrote: > Eduard

Re: [Tutor] Looping, and Win32com.client

2008-12-19 Thread Tim Golden
Eduardo Vieira wrote: Hello, this is my first post in this list and I'm not a programmer, but am enjoying learning python. I'm trying to make a script to add worksheets to excel files: I managed to implement this code: import os folder = 'C:\\Personal\\oldxlsformat\\' from win32com.client import

Re: [Tutor] Looping + Variables

2007-10-21 Thread Martin Walsh
James wrote: > Hi. :) > > I'm trying to write a loop to simplify my life (and code :)). The > loop is going to iterate over a list of values that I have to change > in a file. I think my problem is better described with some code. :) Use a dictionary instead of a tuple ... # variables editVal

Re: [Tutor] looping problem

2006-09-23 Thread Kent Johnson
John Fouhy wrote: > On 24/09/06, Python <[EMAIL PROTECTED]> wrote: >> slices may be the best way to go >> listA = biglist[0::3] # start from index 0 taking every third element >> listB = biglist[2::3] # start from index 2 taking every third element > > I'm not certain they would be.. If you do

Re: [Tutor] looping problem

2006-09-23 Thread John Fouhy
On 24/09/06, Python <[EMAIL PROTECTED]> wrote: > slices may be the best way to go > listA = biglist[0::3] # start from index 0 taking every third element > listB = biglist[2::3] # start from index 2 taking every third element I'm not certain they would be.. If you do that, you will: 1. Create

Re: [Tutor] looping problem

2006-09-23 Thread Kent Johnson
kumar s wrote: > hi, > > thank you. this is not a homework question. > > I have a very huge file of fasta sequence. > > I want to create a dictionary where 'GeneName' as key > and sequence of ATGC characters as value > > > biglist = dat.split('\t') > ['GeneName ','','ATTAAGG

Re: [Tutor] looping problem

2006-09-23 Thread jim stockford
#!/usr/bin/python # or whatever is the absolute path to python on your system counter = 0 for i in "a","b","c","d","e","f","g" : if counter%3 == 0 : print i + " list one ", counter, counter%3 if counter%3 == 1 : print i + " list two ", counter, cou

Re: [Tutor] looping problem

2006-09-23 Thread Python
On Sat, 2006-09-23 at 09:03 -0700, kumar s wrote: > hi, > > thank you. this is not a homework question. > > I have a very huge file of fasta sequence. > > > GeneName \t > AATTAAGGAA.. > > > > > > (1000 lines) > AATAAGGA > >GeneName \t > GGAG

Re: [Tutor] looping problem

2006-09-23 Thread Bob Gailer
kumar s wrote: > [snip] > so I want to select 0,3,6,9 elements into listA > and 2,5,8,11 and so on elements into listB > > Here's a hint: for j in range(0, len(biglist), 3): # this will set j = 0, 3, 6, etc. -- Bob Gailer 510-978-4454 ___ Tutor mai

Re: [Tutor] looping problem

2006-09-23 Thread kumar s
hi, thank you. this is not a homework question. I have a very huge file of fasta sequence. > GeneName \t AATTAAGGAA.. (1000 lines) AATAAGGA >GeneName \t GGAGAGAGATTAAGAA (15000 lines) when I read this as: f2= open('myfile','r') dat = f2.

Re: [Tutor] looping problem

2006-09-23 Thread jim stockford
keep a counter in your loop. is this a homework question? On Sep 23, 2006, at 8:34 AM, kumar s wrote: > hi, > > the reason could be that I did not quite understand > the concept of looping > > I have a list of 48 elements > > I want to create another two lists , listA and listB > > I want to loo

Re: [Tutor] Looping over lists of objects

2006-04-24 Thread Danny Yoo
On Mon, 24 Apr 2006, Etrade Griffiths wrote: > just feeling my way into Python with a small app that reads data from > file, creates objects using that data, stores the objects in a list, > loops over the list doing comparison tests to filter out various > objects. Here is a code snippet: >

Re: [Tutor] Looping over lists of objects

2006-04-24 Thread Etrade Griffiths
Ed the problem is that my original code did not have the closing brackets for the method calls get_a and get_b whereas the code snippet I posted did. That's probably why your version works and mine failed. Thanks for your help! Alun At 17:19 24/04/2006, Ed Singleton wrote: >On 24/04/06, Etr

Re: [Tutor] Looping over lists of objects

2006-04-24 Thread Ed Singleton
On 24/04/06, Etrade Griffiths <[EMAIL PROTECTED]> wrote: > Hi > > just feeling my way into Python with a small app that reads data from > file, creates objects using that data, stores the objects in a list, loops > over the list doing comparison tests to filter out various objects. Here is > a