On Wednesday February 10 2010 14:32:52 Owain Clarke wrote: > My son was doing a statistics project in which he had to sort some data by > either one of two sets of numbers, representing armspan and height of a > group of children - a boring and painstaking job. I came across this > piece of code:- > > li=[[2,6],[1,3],[5,4]] # would also work with li=[(2,6),(1,3),(5,4)] > li.sort(key=lambda x:x[1] ) > print li > > It occurred to me that I could adapt this so that he could input his data > at the command line and then sort by x:x[0] or x:x[1]. And I have not > discovered a way of inputting a list, only strings or various number > types.
I would let him enter the data into the program text directly, or parse a text file with a simple format. Something like: in_data = [ #arm span, height [2 , 6 ], [1 , 3 ], [5 , 4 ], [ , ], [ , ], [ , ], ] This way the computation can be repeated when there were errors int the data. Otherwise one error might spoil all the work he did while typing in the data. Designing a simple text representation of the data and interpreting it with a computer program, is much more easy that writing good user interfaces. For the same reason Unix, a concept from the late 1960s, is still doing relatively well. Eike. _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
