Re: [Tutor] Calculate hours
On 01/22/2013 11:18 PM, anthonym wrote: Thanks Dave I think I would like to keep it simple. How would I get it to repeat and print before deleting? To repeat something, write a loop. So you have a while loop *outside* the one you've written (you'll have to indent your present loop another level). The condition for the while loop is simply a test to see if matrix has any elements in it. So your outer loop loops till the matrix is empty. Inside the loop, determine the minimum element, print it out, then delete it. If you're familiar with functions yet, then move the inner loop into its own function, and it'll read more clearly. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calculate hours
On 23/01/13 03:08, Mitya Sirenef wrote: To make the change you need, use list comprehension to make sums of all rows, sort it (using list sort method); iterate over it using enumerate() and print out "employee N, sum of hours:" One problem with that approach is that the employees are identified by their index in the original row so you probably need to maintain a note of that index. So before sorting you might want to create a tuple with the id and the values then sort on the second element. Only slightly more complex... hth. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calculate hours
On 01/23/2013 06:13 PM, Alan Gauld wrote: On 23/01/13 03:08, Mitya Sirenef wrote: To make the change you need, use list comprehension to make sums of all rows, sort it (using list sort method); iterate over it using enumerate() and print out "employee N, sum of hours:" One problem with that approach is that the employees are identified by their index in the original row so you probably need to maintain a note of that index. So before sorting you might want to create a tuple with the id and the values then sort on the second element. Only slightly more complex... Complex or not, the first question is whether the OP's class has covered sorting yet. And especially supplying key functions. I suspect not. BTW, if I were building the tuples, I'd just let the key value be first, and the index be second. That way the default key function works great. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calculate hours
On 01/23/2013 06:13 PM, Alan Gauld wrote: On 23/01/13 03:08, Mitya Sirenef wrote: > >> To make the change you need, use list comprehension to make sums of all >> rows, sort it (using list sort method); iterate over it using >> enumerate() and print out "employee N, sum of hours:" > > One problem with that approach is that the employees are identified by their index in the original row so you probably need to maintain a note of that index. So before sorting you might want to create a tuple > with the id and the values then sort on the second element. Only slightly more complex... > > hth. > Oh, that's right - thanks for catching this. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ The best author will be the one who is ashamed to become a writer. Friedrich Nietzsche ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calculate hours
Thanks Dave. I forgot to hit the reply to all last time. I am going to try the loop when I get back home and will let you know how I make out. Also we have done some functions. Sort and append being among them. I try the simplest way first then stream line later. Probably not the fastest way. Tony On 1/23/13 3:05 PM, "Dave Angel" wrote: >You posted this privately to me. It should have been a message to the >forum, with tutor@python.org as its to: field. > >On 01/23/2013 10:42 AM, anthonym wrote: >> Should the outside loop have a print command in it so I don't loose that >> information like I do now? >> > >Yes, the print and the delete are technically in the outer loop. I was >thinking in terms of a function, in which case I probably would have >included those two elements in the function. But my wording was wrong. > >Can you write an attempted solution, and post it to the thread, along >with whatever difficulty you still see? > >Rough pseudo-code > >while something-in-list > find minimum element (this is a loop, similar to the one you >already wrote) > print out whatever you need from that element > delete that element > >print out "success" > > > >-- >DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Small personal project to fill CDs/DVDs...
Need to fill some DVDs. Figured Python would be the tool to quickly write this tool in, since I have seen similar tools written in python. I even found something onlist to start from... from August 2004. Sent: Sunday, August 15, 2004 9:22 PM Subject: Re: [Tutor] List files in directory "Bernard Lebel" wrote: > > Hello, > > Anyone has advice on how to collect filenames from a directory? > I want to print only the files contains in the currently visited directory. This is simple enough that I can help: import os path="C:\\somedirectory" # insert the path to the directory of interest here dirList=os.listdir(path) for fname in dirList: print fname I have lots of DOS, Unix and Linux scripts, as well as 30 years of development in all types of environments. I am currently looking to create a python application that works on many different platforms, but can work without problems on Windows (ALL), Linux (ALL) using Gtk/xfce/other (need suggestions), and Unix (really need suggestions). Need help in defining environment standards to research learn, and looking for pointers in modules to use developing my new open source app. ;) Scratchy overview -- Full solution for me will accept start directory and -c or -d parm (CD/DVD) if passed from command line or shell script. If start directory is not passed, there will be a "browse" interface to choose the directory to start from (will determine OS from os call) and a media drop-down selection. Will require a standard GUI environment like windows/gtk/"something". The main process will create a list of fully-qualified file names, file sizes. Then, it will build a grouped list of files, filling media as effectively as possible. Last, it will print on screen the lists of FQFNs and filesizes that will go on each backup disk. Should be just a list of simple printfs. I have done some maintenance on python, but this is the first app that I have written from scratch, so I need to focus on each area -- Barry Smith Secure Computer Services c 704-497-4217 e bnsmith...@gmail.com e scs.bns...@gmail.com w1 http://bit.ly/l8QJup w2 http://scs-llc.info/ DUNS 83-099-9384 EIN 27-4523550 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor