Re: [Tutor] Problem with installing python
I was trying to install Python 2.7 on my Windows 8.1(x64) PC and got the following error: "There is a problem with this Windows Istaller Package.A DLL required for this install to complete could not be run.Contact your support personnel or package vendor." Please help! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problem with installing python
On 05/06/15 07:45, Aditya Shaw wrote: I was trying to install Python 2.7 on my Windows 8.1(x64) PC and got the following error: "There is a problem with this Windows Istaller Package.A DLL required for this install to complete could not be run.Contact your support personnel or package vendor." It may be a corrupt download. Since you are using Windows I recommend using the installer from Activestate.com rather than the python.org version since it includes several useful extras for Windows users. Try a fresh download from activestate.com and see if that installs. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] line iteration in a file
SOLVED: Sometimes one just has to be an idiot. One must remember that computers count from zero, not from one. Changes my list indexes to reflect that small but crucial fundamental point, and all worked fine. regards, Richard On Wed, Jun 3, 2015 at 10:37 PM, richard kappler wrote: > Figured out the string delimiters problem, thanks for all the help. Now > I've run into another. > > I've used the re.finditer that I think it was Peter suggested. So I have: > > for line in file: > s = line > t = [m.start() for m in re.finditer(r"]", s)] > q = len(t) > > which works fine, in testing it finds the number and position of the ]'s > in any line I throw at it. I then wrote a series of if/elif statements > based on q, in other words > > if q == 1: > do something > elif q == 2: > do something else > elif q == 3: > do a third thing > else: > pass > > as I looked through enough example to figure out that the most ]'s I can > have is 3, but the pass is there just in case. > > I keep getting a list index out of range error, and my best guess is that > it's because t and q are set on the first line read, not each line read, is > that right? If not, what might be the problem and either way, how do I fix > it? > > regards, Richard > who is proving to his Linux box that he is an idiot pretty regularly > -- > > Windows assumes you are an idiot…Linux demands proof. > -- Windows assumes you are an idiot…Linux demands proof. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Sorting a list of list
As part of my league secretary program (to which thread I shall reply again shortly), I need to sort a list of lists. I've worked out that I can use sorted() and operator.itemgetter to sort by a value at a known position in each list. Is it possible to do this at a secondary level? So if the items are the same, we use the secondary key? Current function: >>> def sort_table(table, col=0): ... return sorted(table, key=operator.itemgetter(col), reverse=True) ... >>> sort_table(results, 6) [['spip', 2, 2, 0, 10, 0, 4], ['hpip', 2, 0, 2, 2, 8, 0]] S. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Sorting a list of list
Stephen Nelson-Smith wrote: > As part of my league secretary program (to which thread I shall reply > again > shortly), I need to sort a list of lists. I've worked out that I can use > sorted() and operator.itemgetter to sort by a value at a known position in > each list. Is it possible to do this at a secondary level? So if the > items are the same, we use the secondary key? > > Current function: > def sort_table(table, col=0): > ... return sorted(table, key=operator.itemgetter(col), reverse=True) > ... sort_table(results, 6) > [['spip', 2, 2, 0, 10, 0, 4], ['hpip', 2, 0, 2, 2, 8, 0]] itemgetter() accepts multiple indices: >>> items = [ ... ["one", "stephen", 20], ... ["two", "stephen", 10], ... ["three", "jim", 20]] >>> from operator import itemgetter >>> sorted(items, key=itemgetter(1, 2)) [['three', 'jim', 20], ['two', 'stephen', 10], ['one', 'stephen', 20]] >>> sorted(items, key=itemgetter(2, 1)) [['two', 'stephen', 10], ['three', 'jim', 20], ['one', 'stephen', 20]] For complex sort orders you can build on the fact that Python's sort is "stable", i. e. equal items do not change their relative position. Just sort by the "least significan key" first: >>> items.sort(key=itemgetter(2), reverse=True) >>> items.sort(key=itemgetter(1)) >>> items [['three', 'jim', 20], ['one', 'stephen', 20], ['two', 'stephen', 10]] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Sorting a list of list
On 05/06/2015 21:16, Stephen Nelson-Smith wrote: As part of my league secretary program (to which thread I shall reply again shortly), I need to sort a list of lists. I've worked out that I can use sorted() and operator.itemgetter to sort by a value at a known position in each list. Is it possible to do this at a secondary level? So if the items are the same, we use the secondary key? Current function: def sort_table(table, col=0): ... return sorted(table, key=operator.itemgetter(col), reverse=True) ... sort_table(results, 6) [['spip', 2, 2, 0, 10, 0, 4], ['hpip', 2, 0, 2, 2, 8, 0]] S. Asked myself the very same thing earlier today so had the answer at my fingertips, taken from https://docs.python.org/3/howto/sorting.html The operator module functions allow multiple levels of sorting. For example, to sort by grade then by age: >>> >>> sorted(student_tuples, key=itemgetter(1,2)) [('john', 'A', 15), ('dave', 'B', 10), ('jane', 'B', 12)] -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Sorting a list of list
In a message of Fri, 05 Jun 2015 21:16:33 +0100, Stephen Nelson-Smith writes: >As part of my league secretary program (to which thread I shall reply again >shortly), I need to sort a list of lists. I've worked out that I can use >sorted() and operator.itemgetter to sort by a value at a known position in >each list. Is it possible to do this at a secondary level? So if the >items are the same, we use the secondary key? Certainly. see: https://wiki.python.org/moin/HowTo/Sorting Laura ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor