Re: [Tutor] permutations?

2010-12-02 Thread Alan Gauld
"Alex Hall" wrote Alright, I have it working. Now the problem is that it does not throw out reversals. I tried to do this myself with a couple loops, but I get index errors. My total list of permutations is called l. for i in range(0, len(l)): r=l[i]; r.reverse() You don''t need to specify

Re: [Tutor] data structures

2010-12-02 Thread Alan Gauld
"Dana" wrote I'm using Python to extract words from plain text files. I have a list of words. Now I would like to convert that list to a dictionary of features where the key is the word and the value the number of occurrences in a group of files based on the filename I think I know what

[Tutor] a print puzzle

2010-12-02 Thread Richard D. Moores
>>> s = [.1,.1,.1,.1,.1,.1,.1,.1,.1,.1] >>> sum(s) 0. >>> print(sum(s)) 1.0 Why? >>> f = 0. >>> f**100 0.9889 >>> print(f**100) 1.0 Why? >>> f**1 0.99988898 >>> print(f**1) 0. >>> from math import fsum >>> fsum(s) 1.0

Re: [Tutor] a print puzzle

2010-12-02 Thread Alan Gauld
"Richard D. Moores" wrote s = [.1,.1,.1,.1,.1,.1,.1,.1,.1,.1] sum(s) 0. This uses repr() to display the result print(sum(s)) 1.0 Why? This uses str() to display the result. In many cases str() calls repr() but in other cases str() is a more user friendly format.

Re: [Tutor] permutations?

2010-12-02 Thread Peter Otten
Alex Hall wrote: > 1. Order matters; I meant to say that direction does not. That is, 123 > is not the same as 213, but 123 is the same as 321 since the second > example is simply a reversal. > 2. I am looking for all permutations and subpermutations (if that is a > word) of 1-n where the list mus

Re: [Tutor] permutations?

2010-12-02 Thread शंतनू
Following link could be useful: http://stackoverflow.com/questions/104420/how-to-generate-all-permutations-of-a-list-in-python On Thu, Dec 2, 2010 at 04:15, Alex Hall wrote: > Hi all, > I am wondering if there is a python package that will find > permutations? For example, if I have (1, 2, 3),

Re: [Tutor] permutations?

2010-12-02 Thread Luke Paireepinart
Instead of nested fors which will grow exponentially in running time, consider this for removing reversals: newlist = [] tempdict = {} for i in oldlist: try: tempdict[i] except: tempdict[i] = 1 tempdict[i.reverse()] = 1 newlist.append(i) That's the gneral

[Tutor] Trying To Debug Code That Runs Arbitrary Function

2010-12-02 Thread Homme, James
Hi, If you can get away with not telling me the answer, but pointing me to where to look for the answer, I'd be grateful. In my Python learning, I am just now starting to understand how to make classes and extend them, so I have a very long way to go. I wrote this code because I wanted to avoid

Re: [Tutor] Trying To Debug Code That Runs Arbitrary Function

2010-12-02 Thread Vern Ceder
Here's your hint... to execute a Python function, it must be followed by parentheses otherwise you are just referring to the function object. HTH, Vern On Thu, Dec 2, 2010 at 9:35 AM, Homme, James wrote: > Hi, > > If you can get away with not telling me the answer, but pointing me to > whe

Re: [Tutor] Trying To Debug Code That Runs Arbitrary Function

2010-12-02 Thread Alan Gauld
"Homme, James" wrote If you can get away with not telling me the answer, but pointing me to where to look for the answer, I'd be grateful. OK, Don't use eval or exec they have secuity issues - especially if reading the strings from a file! idea is to read in strings from a file, look one

[Tutor] Is there any way I can use named tuples in Python 2.5?

2010-12-02 Thread Albert-Jan Roskam
Hi, Is there any way I can use named tuples in Python 2.5? It's available since 2.6 and I'm not sure if from "__future__" works. I can't try it here. I cannot simply upgrade Python (alas!) http://www.python.org/doc//current/library/collections.html#collections.namedtuple Cheers!! Albert-Jan

Re: [Tutor] a print puzzle

2010-12-02 Thread Richard D. Moores
On Thu, Dec 2, 2010 at 03:13, Alan Gauld wrote: > > "Richard D. Moores" wrote > > s = [.1,.1,.1,.1,.1,.1,.1,.1,.1,.1] > sum(s) >> >> 0. > > This uses repr() to display the result > > print(sum(s)) >> >> 1.0      Why? > > This uses str() to display the result. > > In ma

Re: [Tutor] Is there any way I can use named tuples in Python 2.5?

2010-12-02 Thread Emile van Sebille
On 12/2/2010 9:52 AM Albert-Jan Roskam said... Hi, Is there any way I can use named tuples in Python 2.5? It's available since 2.6 and I'm not sure if from "__future__" works. I can't try it here. I cannot simply upgrade Python (alas!) Maybe this'll help... http://code.activestate.com/recipes

Re: [Tutor] Is there any way I can use named tuples in Python 2.5?

2010-12-02 Thread Albert-Jan Roskam
Hi, Thank you! Woaah, very cool code btw. There's much to learn from it, for me at least. Cheers!! Albert-Jan ~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fre

Re: [Tutor] a print puzzle

2010-12-02 Thread bob gailer
On 12/2/2010 2:09 PM, Richard D. Moores wrote: [snip] I found nothing that helped as much as you have already. In the reference (for 2.6.2) under print statement I find: "print evaluates each expression in turn and writes the resulting object to standard output (see below). If an object is

Re: [Tutor] a print puzzle

2010-12-02 Thread Steven D'Aprano
bob gailer wrote: On 12/2/2010 2:09 PM, Richard D. Moores wrote: [snip] I found nothing that helped as much as you have already. In the reference (for 2.6.2) under print statement I find: "print evaluates each expression in turn and writes the resulting object to standard output (see below

[Tutor] Scanning a file for specific text and copying it to a new file

2010-12-02 Thread Ben Ganzfried
I'm trying to build a program that reads in a file and copies specific sections to a new file. More specifically, every time the words "summary on" are in the original file, I want to copy the following text to the new file until I get to the words "summary off". My questions are the following: 1

Re: [Tutor] Scanning a file for specific text and copying it to a new file

2010-12-02 Thread Emile van Sebille
On 12/2/2010 10:27 AM Ben Ganzfried said... I'm trying to build a program that reads in a file and copies specific sections to a new file. More specifically, every time the words "summary on" are in the original file, I want to copy the following text to the new file until I get to the words "su

Re: [Tutor] Scanning a file for specific text and copying it to a new file

2010-12-02 Thread Steven D'Aprano
Ben Ganzfried wrote: I'm trying to build a program that reads in a file and copies specific sections to a new file. More specifically, every time the words "summary on" are in the original file, I want to copy the following text to the new file until I get to the words "summary off". My questio

Re: [Tutor] Scanning a file for specific text and copying it to a newfile

2010-12-02 Thread Alan Gauld
"Ben Ganzfried" wrote I'm trying to build a program that reads in a file and copies specific sections to a new file. More specifically, every time the words "summary on" are in the original file, I want to copy the following text to the new file until I get to the words "summary off". This

Re: [Tutor] data structures

2010-12-02 Thread Steven D'Aprano
Knacktus wrote: Am 02.12.2010 02:51, schrieb Dana: Hello, I'm using Python to extract words from plain text files. I have a list of words. Now I would like to convert that list to a dictionary of features where the key is the word and the value the number of occurrences in a group of files base

Re: [Tutor] Pyserial and invalid handle

2010-12-02 Thread Terry Carroll
On Wed, 1 Dec 2010, Walter Prins wrote: But whatever the case may be, suffice it to say I've reproduced your issue on my Win7 64bit box, and then resolved it by installing the PyWin32 modules. I'd like to put in a plug for Activestate Python here. Activestate has a free distribution of Pytho

Re: [Tutor] permutations?

2010-12-02 Thread Steven D'Aprano
Alan Gauld wrote: "Alex Hall" wrote Alright, I have it working. Now the problem is that it does not throw out reversals. I tried to do this myself with a couple loops, but I get index errors. My total list of permutations is called l. for i in range(0, len(l)): r=l[i]; r.reverse() You don'

[Tutor] printing in python 3.x

2010-12-02 Thread Rance Hall
I've been working on this cli based python 3.x app for a friends shop. So far, everything is working well. We are now ready to start development on a new module of my code. The shop is a repair shop, and I've already done the code for client management and employee management and all the framewo