Re: [Tutor] Hello again. Still the same problem, different question.

2011-11-11 Thread Andreas Perstinger

On 2011-11-12 05:16, Nathaniel Trujillo wrote:

They gave me a website to go and download a version of
livewires that would work (www.courseptr.com/downloads) and I went there
but I could not find that download anywhere.


http://www.delmarlearning.com/companions/content/1435455002/downloads/index.asp?isbn=1435455002
If you click on "Book related software" you'll get a zip-file which 
includes "livewires".


Bye, Andreas
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello again. Still the same problem, different question.

2011-11-11 Thread Steven D'Aprano

Nathaniel Trujillo wrote:

I realize that one of you told me that there is no livewires for python
v3.1.1 but the book that I am reading teaches v3.1.1 and the code that is
presented in the book has a line that imports a module from the livewires
package. Now since the book covers v3.1.1, I would have to conclude that
the code containing the line "from livewires import games" should work in
version 3.1.1. They gave me a website to go and download a version of
livewires that would work (www.courseptr.com/downloads) and I went there
but I could not find that download anywhere. I think the website might have
changed since the book was written. If anybody knows where I can get the
version of livewires I need I would be truly greatful. My book is entitled
Python Programming for the Absolute Beginner Third Edition. Anyway, here is
the code that my book insists should work.


According to one of the reviews on Amazon, that's because the author of 
the book has written his own customized version of Livewires which you 
have to use.


http://www.amazon.ca/Python-Programming-Absolute-Beginner-Second/dp/1598631128

The book quite clearly says so too:

TRAP Although you're welcome to visit the web site of the LiveWires
 organization at http://www.livewires.org.uk , be aware that the 


 livewires package used in this book is a modified version of the
 package that LiveWires created.




Someone there told me they would've given up by now but I am not giving up
on this one or anything else. Just to give you a heads up, you will be
getting questions about this until this program works. Thanks for your help.


While I admire your persistence, we are all volunteers and may not 
appreciate being asked the same questions over and over and over again 
to no value.


I'm just saying that at some point, you may have to expect that we'll 
stop answering questions if we think we're just wasting our time. If the 
author's custom version is not available, and the standard version 
doesn't work, then we're probably wasting our time.




--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello again. Still the same problem, different question.

2011-11-11 Thread delegbede
Can you kindly mail the author?
That might be a better way to have this resolved. 
Its interesting you are sticking with python v3. 
Cheers. 
Sent from my BlackBerry wireless device from MTN

-Original Message-
From: Nathaniel Trujillo 
Sender: tutor-bounces+delegbede=dudupay@python.org
Date: Fri, 11 Nov 2011 21:16:30 
To: 
Subject: [Tutor] Hello again. Still the same problem, different question.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Hello again. Still the same problem, different question.

2011-11-11 Thread Nathaniel Trujillo
I realize that one of you told me that there is no livewires for python
v3.1.1 but the book that I am reading teaches v3.1.1 and the code that is
presented in the book has a line that imports a module from the livewires
package. Now since the book covers v3.1.1, I would have to conclude that
the code containing the line "from livewires import games" should work in
version 3.1.1. They gave me a website to go and download a version of
livewires that would work (www.courseptr.com/downloads) and I went there
but I could not find that download anywhere. I think the website might have
changed since the book was written. If anybody knows where I can get the
version of livewires I need I would be truly greatful. My book is entitled
Python Programming for the Absolute Beginner Third Edition. Anyway, here is
the code that my book insists should work.

# New Graphics Window
# Demonstrates creating a graphics window
from livewires import games
games.init(screen_width = 640, screen_height = 480, fps = 50)
games.screen.mainloop()
and here is the error message I keep getting

Traceback (most recent call last):
  File "C:\Python27\new_graphics_window.py", line 6, in 
games.init(screen_width = 640, screen_height = 480, fps = 50)
AttributeError: 'module' object has no attribute 'init'

Someone there told me they would've given up by now but I am not giving up
on this one or anything else. Just to give you a heads up, you will be
getting questions about this until this program works. Thanks for your help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] My program gives no output (was (no subject)

2011-11-11 Thread bob gailer

Welcome to the Tutor list.

Please provide a meaningful subbject as we track posts by subject

On 11/11/2011 4:40 PM, Nic Jaworski wrote:

python: v. 2.7.1
Compiler: WING IDE
OS: Windows 7

I am attempting to use a loop to output a 2D array for days and amount 
of pennies.  I have it set to loop to do a penny times the day then to 
double the the penny and add a day. (the whole a penny doubles each 
day problem). However when I run my program I don't get anything, no 
output.


IMHO you cannot get nothing. You should either get some error message or 
at least "how many days for your salary?"


Exactly what do you do to run the program?



#Nic  11/5/2011
#Penny +=1 Each Day

from math import *
from numberTest import *
from clearPause import *
from locale import *


I highly recommend not using from...  import *
Instead import ... and qualify the imported items.

I am not familiar with numberTest or clearPause.
Where did you find them?


#=Main


def main():
days=indays()
salary = calc(days)
#=== Days input
def indays():
integer=0
while integer==0:
salary = raw_input("how many days for your salary? ")
integer,salary=testinteger(salary)
if integer ==0:
print 'the entry was not numeric - Please re-enter'
pause()
elif salary < 0:
print 'please enter a number greater then 0'
integer =0
else:
integer=1
return salary

#=Calculation

def calc(days):
n=0
d=1
while n>days:
n+1
d**(n)
d*2
x = array ([d,n])
print x
main()


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Suggest Book

2011-11-11 Thread Alan Gauld

On 11/11/11 14:29, Pankaj Jakhar wrote:


Please suggest me the best book for Python from which I can learn basics
to advanced Python.


The "best" book will depend on you, some like informal chatty style with 
lots of examples other prefer a more formal approach. For me the 
O'Reilly books get it about right, although APress and Addison Wesley 
are usually safe bets too.


It will also depend on your previous experience - do you already program 
in another language? Do you have any formal computer science or 
engineering or math background? These are all things that will affect 
your preference.


Try browsing on Amazon and other web sites, use the previews where 
available...


One other thing to consider os that "advanced" Python tends to be a case 
of a specialized subject area/library rather than advanced language 
usage., Python is pretty  simple to use at any levels. You can write 
obscure python but its not often good Python and possibly not even 
advanced! So you might be better focusing on on-line tutorials to 
start with then choosing a specialized book to suit your interests - 
like networking, web, GUI, text processing, Games etc.

--
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] (no subject)

2011-11-11 Thread Andreas Perstinger

Please just post plain-text (no html) and use a meaningful subject!

On 2011-11-11 22:40, Nic Jaworski wrote:

def calc(days):
  n=0
  d=1
  while n>days:
n+1
d**(n)
d*2


You are just calculating some expressions with "n" and "d" but you don't 
assign the results. Thus "n" and "d" will never change.



x = array ([d,n])
print x


In "main()" you have the line

salary = calc(days)

but you just return "None" (the default value for functions without a 
"return" statement) from "calc()". Is that what you want?



main()


I don't know about windows but if you want to run the script from the 
command line you have to add:


if __name__ == "__main__":
   main()

See 
http://docs.python.org/py3k/tutorial/modules.html#executing-modules-as-scripts


Bye, Andreas
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2011-11-11 Thread Joel Goldstick
On Fri, Nov 11, 2011 at 4:40 PM, Nic Jaworski wrote:

>  python: v. 2.7.1
> Compiler: WING IDE
> OS: Windows 7
>
> I am attempting to use a loop to output a 2D array for days and amount of
> pennies.  I have it set to loop to do a penny times the day then to double
> the the penny and add a day. (the whole a penny doubles each day
> problem). However when I run my program I don't get anything, no output.
>
> #Nic  11/5/2011
> #Penny +=1 Each Day
>
> from math import *
> from numberTest import *
> from clearPause import *
> from locale import *
> #=Main
>
>
> def main():
> days=indays()
> salary = calc(days)
>
> #=== Days input
> def indays():
> integer=0
> while integer==0:
> salary = raw_input("how many days for your salary? ")
> integer,salary=testinteger(salary)
> if integer ==0:
> print 'the entry was not numeric - Please re-enter'
> pause()
> elif salary < 0:
> print 'please enter a number greater then 0'
> integer =0
> else:
> integer=1
> return salary
>
> #=Calculation
>
> def calc(days):
>


You are setting n = 0, then you loop only if n > days, and it never is.




> n=0
> d=1
> while n>days:
> n+1
> d**(n)
> d*2
> x = array ([d,n])
> print x
>
>
> main()
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Joel Goldstick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] longest common substring

2011-11-11 Thread Andreas Perstinger

First, just a little rant :-)
It doesn't help to randomly change some lines or introduce some new 
concepts you don't understand yet and then hope to get the right result. 
Your chances are very small that this will be succesful.

You should try to understand some basic concepts first and build on them.
From your postings the last weeks and especially from today I have the 
impression that you still don't understand how fundamental programming 
concepts work: for-loops, differences between data types (strings, 
lists, sets, ...)
Honestly, have you already read any programming tutorial? (You'll find a 
big list at http://wiki.python.org/moin/BeginnersGuide/NonProgrammers )? 
At the moment it looks like you are just copying some code snippets from 
different places and then you hopelessly try to modify them to suit your 
needs. IMHO the problems you want to solve are a little too big for you 
right now.


Nevertheless, here are some comments:


Based on former advice, I made a correction/modification on the below code.

1] the set and subgroup does not work, here I wish to put all the
subgroup in a big set, the set like


That's a good idea, but you don't use the set correctly.

> subgroups=[]
> subgroup=[]
> def LongestCommonSubstring(S1, S2):

I think it's better to move "subgroups" and "subgroup" into the 
function. (I've noticed that in most of your scripts you are using a lot 
of global variables. IMHO that's not the best programming style. Do you 
know what "global/local variables", "namespace", "scope" mean?)


You are defining "subgroups" as an empty list, but later you want to use 
it as a set. Thus, you should define it as an empty set:


subgroups = set()

You are also defining "subgroup" as an empty list, but later you assign 
a slice of "S1" to it. Since "S1" is a string, the slice is also a 
string. Therefore:


subgroup = ""

>  M = [[0]*(1+len(S2)) for i in xrange(1+len(S1))]

Peter told you already why "xrange" doesn't work in Python 3. But 
instead of using an alias like


xrange = range

IMHO it's better to change it in the code directly.

>  longest, x_longest = 0, 0
>  for x in xrange(1,1+len(S1)):
>  for y in xrange(1,1+len(S2)):
>  if S1[x-1] == S2[y-1]:
>  M[x][y] = M[x-1][y-1]+1
>  if M[x][y]>  longest:
>  longest = M[x][y]
>  x_longest = x
>  if longest>= 3:
>  subgroup=S1[x_longest-longest:x_longest]
>  subgroups=set([subgroup])

Here you overwrite in the first iteration your original empty list 
"subgroups" with the set of the list which contains the string 
"subgroup" as its only element. Do you really understand this line?
And in all the following iterations you are overwriting this one-element 
set with another one-element set (the next "subgroup").
If you want to add an element to an existing set instead of replacing 
it, you have to use the "add()"-method for adding an element to a set:


subgroups.add(subgroup)

This will add the string "subgroup" as a new element to the set "subgroups".

>  print(subgroups)
>  else:
>  M[x][y] = 0
>
>  return S1[x_longest-longest:x_longest]

Here you probably want to return the set "subgroups":

return subgroups



2] I still have trouble in reading files, mainly about not read "" etc.


The problem is that in your data files there is just this big one-line 
string. AFAIK you have produced these data files yourself, haven't you? 
In that case it would be better to change the way how you save the data 
(be it a well-formatted string or a list or something else) instead of 
trying to fix it here (in this script).


Bye, Andreas
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2011-11-11 Thread Nic Jaworski

python: v. 2.7.1Compiler: WING IDEOS: Windows 7
I am attempting to use a loop to output a 2D array for days and amount of 
pennies.  I have it set to loop to do a penny times the day then to double the 
the penny and add a day. (the whole a penny doubles each day problem). However 
when I run my program I don't get anything, no output.
#Nic  11/5/2011#Penny +=1 Each Day
from math import *from numberTest import *from clearPause import *from locale 
import *#=Main

def main():days=indays()salary = calc(days)
#=== Days inputdef indays():integer=0while 
integer==0:salary = raw_input("how many days for your salary? ")
integer,salary=testinteger(salary)if integer ==0:print 'the 
entry was not numeric - Please re-enter'pause()elif salary 
< 0:print 'please enter a number greater then 0'integer 
=0else:integer=1return salary
#=Calculation
def calc(days):n=0d=1while n>days:n+1d**(n)
d*2  x = array ([d,n])print x   main()  
   ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Suggest Book

2011-11-11 Thread Evans Anyokwu
You really don't need a book. There are tons of free materials online
including Alan's excellent tutorial. Spend some time working your way
through some of these free tutorials, and once  you're comfortable enough
writing Python programs then buy one or two books as a reference material.

Good luck,
Evans
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Find all strings that....

2011-11-11 Thread Albert-Jan Roskam
hi,

this page contains interesting info about this topic. The algorithms that are 
discussed are all implemented in Python.

http://cs.anu.edu.au/~Peter.Christen/Febrl/febrl-0.3/febrldoc-0.3/node38.html

 
Cheers!!
Albert-Jan


~~
All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a fresh water system, and public health, what have 
the Romans ever done for us?
~~


>
>From: Jerry Hill 
>To: "tutor@python.org" 
>Sent: Friday, November 11, 2011 7:38 PM
>Subject: Re: [Tutor] Find all strings that
>
>
>On Fri, Nov 11, 2011 at 1:21 PM, Francesco Loffredo  wrote:
>
>Anyway, taking for granted the rules contained in the edit distance definition 
>(Thank you, Steven!), I think that finding in a given set S all words that can 
>be converted into some given "target" with at most N such operations (better:  
>the subset of all words in S with an edit distance from "target" <= N) is a 
>very interesting and challenging task. Thank you (and your friend!) for this 
>exercise, I'll give it a try.
>>
>There are some standard library tools that make this pretty easy.  Take a look 
>into difflib if you're interested.  As always, there's nothing wrong with 
>doing it yourself so that you understand it better, of course.
>
>-- 
>Jerry
>
>___
>Tutor maillist  -  Tutor@python.org
>To unsubscribe or change subscription options:
>http://mail.python.org/mailman/listinfo/tutor
>
>
>___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Find all strings that....

2011-11-11 Thread Alexander
On Fri, Nov 11, 2011 at 1:38 PM, Jerry Hill  wrote:

> On Fri, Nov 11, 2011 at 1:21 PM, Francesco Loffredo  wrote:
>
>> Anyway, taking for granted the rules contained in the edit distance
>> definition (Thank you, Steven!), I think that finding in a given set S all
>> words that can be converted into some given "target" with at most N such
>> operations (better:  the subset of all words in S with an edit distance
>> from "target" <= N) is a very interesting and challenging task. Thank you
>> (and your friend!) for this exercise, I'll give it a try.
>>
>
> There are some standard library tools that make this pretty easy.  Take a
> look into difflib if you're interested.  As always, there's nothing wrong
> with doing it yourself so that you understand it better, of course.
>
> --
> Jerry
>
> Hi Jerry. I'm checking out difflib. Thanks for the suggestion.
Alexander Etter

> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Find all strings that....

2011-11-11 Thread Jerry Hill
On Fri, Nov 11, 2011 at 1:21 PM, Francesco Loffredo  wrote:

> Anyway, taking for granted the rules contained in the edit distance
> definition (Thank you, Steven!), I think that finding in a given set S all
> words that can be converted into some given "target" with at most N such
> operations (better:  the subset of all words in S with an edit distance
> from "target" <= N) is a very interesting and challenging task. Thank you
> (and your friend!) for this exercise, I'll give it a try.
>

There are some standard library tools that make this pretty easy.  Take a
look into difflib if you're interested.  As always, there's nothing wrong
with doing it yourself so that you understand it better, of course.

-- 
Jerry
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Find all strings that....

2011-11-11 Thread Francesco Loffredo

Alexander Etter wrote:

On Nov 10, 2011, at 13:52, Francesco Loffredo  wrote:


Alexander Etter wrote:

Hi. My friend gave me a good wake up exercise ...

I'd like to try this exercise too; would you mind defining "operations" more 
specifically, please?
Given a sufficiently broad meaning of "operations" (e.g. operation = any 
function call)
then any word can be converted into any given word with at most ONE operation.

Consider an operation not as a function. A function could easily contain more 
than two operations. An operation would remove two letters. An operation would 
add one letter. Etc.
Alexander
Still, it seems to me too fuzzy a definition. Steven D'Aprano gave us a very thorough one in this thread, but you seem to allow many 
characters to be deleted in one operation...


Anyway, taking for granted the rules contained in the edit distance definition (Thank you, Steven!), I think that finding in a given 
set S all words that can be converted into some given "target" with at most N such operations (better:  the subset of all words in S 
with an edit distance from "target" <= N) is a very interesting and challenging task. Thank you (and your friend!) for this 
exercise, I'll give it a try.


Francesco


-
Nessun virus nel messaggio.
Controllato da AVG - www.avg.com
Versione: 2012.0.1869 / Database dei virus: 2092/4608 -  Data di rilascio: 
10/11/2011

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] failed to load functions,

2011-11-11 Thread lina
I attached the clumsy one as below:

https://docs.google.com/open?id=0B93SVRfpVVg3YTNhNTMwODUtMDkyYi00ZTk4LThiOGYtMzdkNzI1ZmNhOWQ0


#!/usr/bin/python3

import os.path
from collections import Counter

aList=['55', '34', '77', '43', '58', '34', '77', '34', '76', '34',
'77', '76', '32', '72', '34', '41', '34', '56', '70', '45', '43',
'45', '34', '45', '34', '45', '76', '77', '76', '77', '76', '77',
'76', '77', '76', '77', '76', '77', '82', '43', '77', '34', '77',
'61', '59', '82', '65', '55', '71', '82', '80', '65', '71', '82',
'65', '64', '65', '80', '84', '80', '82', '58', '74', '76', '58',
'76', '74', '76', '57', '34', '57', '77', '34', '52', '84', '34',
'57', '35', '34', '32', '55', '53', '34', '35', '34', '32', '54',
'34', '54', '57', '54', '34', '57', '54', '57', '34', '54', '34',
'54', '57', '54', '34', '57', '54', '34', '32', '34', '57', '34',
'54', '35', '54', '34', '58', '77', '34', '77', '34', '53', '76',
'58', '34', '56', '54', '58', '34', '57', '34', '56', '77', '54',
'56', '34', '77', '76', '77', '76', '77', '53', '77', '56', '34',
'32', '34', '54', '32', '54', '32', '34', '32', '54', '32', '34',
'55', '61', '54', '34', '32', '54', '32', '54', '55', '34', '32',
'34', '54', '34', '55', '32', '54', '34', '57', '54', '34', '54',
'57', '34', '55', '59', '33', '59', '55', '34', '54', '59', '34',
'55', '34', '54', '35', '57', '34', '54', '34', '55', '34', '54',
'57', '55', '54', '34', '57', '34', '33', '34', '20', '54', '55',
'54', '34', '54', '32', '54', '32', '34', '54', '32', '54', '32',
'54', '34', '32', '34', '57', '34', '54', '35', '34', '32', '59',
'34', '54', '34', '55', '33', '34', '55', '34', '35', '34', '54',
'34', '32', '34', '35', '34', '54', '34', '54', '34', '54', '34',
'53', '34', '57', '20', '58', '57', '76', '58', '74', '76', '55',
'59', '57', '34', '57', '34', '77', '34', '54', '56', '34', '56',
'54', '34', '56', '34', '54', '58', '32', '54', '76', '34', '76',
'53', '34', '77', '32', '34', '77', '32', '54', '34', '32', '34',
'57', '34', '32', '55', '32', '54', '32', '34', '54', '55', '54',
'55', '56', '32', '76', '53', '76', '34', '53', '76', '57', '76',
'53', '34', '58', '34', '54', '76', '77', '34', '76', '34', '32',
'34', '35', '32', '34', '53', '76', '53', '57', '53', '34', '76',
'53', '76', '34', '76', '53', '76', '57', '53', '76', '57', '76',
'53', '76']

bList=['77', '34', '60', '84', '76', '34', '76', '34', '46', '59',
'77', '34', '77', '82', '34', '33', '34', '82', '34', '77', '70',
'58', '34', '49', '58', '49', '35', '49', '32', '61', '34', '58',
'61', '58', '61', '35', '61', '70', '61', '70', '61', '34', '20',
'61', '34', '58', '32', '34', '32', '58', '20', '35', '20', '34',
'21', '59', '21', '34', '21', '34', '21', '34', '21', '34', '21',
'34', '21', '34', '21', '34', '21', '34', '21', '34', '21', '34',
'21', '59', '34', '21', '34', '21', '34', '21', '34', '21', '34',
'32', '34', '61', '20', '61', '32', '34', '35', '34', '58', '34',
'58', '32', '34', '58', '46', '20', '32', '61', '20', '34', '58',
'34', '32', '58', '34', '32', '70', '32', '34', '30', '34', '32',
'30', '61', '32', '35', '61', '32', '34', '30', '61', '58', '32',
'20', '34', '20', '32', '61', '30', '20', '61', '20', '83', '35',
'32', '34', '61', '34', '61', '34', '20', '32', '61', '32', '58',
'32', '27', '32', '61', '59', '61', '70', '30', '59', '61', '32',
'83', '30', '32', '34', '33', '80', '32', '35', '80', '59', '80',
'70', '80', '81', '61', '81', '34', '32', '33', '30', '23', '27',
'20', '33', '22', '27', '35', '22', '27', '22', '23', '22', '31',
'22', '35', '22', '33', '22', '35', '33', '22', '31', '35', '22',
'20', '2', '37', '34', '84', '33', '34', '33', '84', '36', '83', '33',
'36', '69', '84', '38', '40', '38', '4', '37', '6', '1', '3', '35',
'3', '38', '27', '3', '5', '3', '5', '27', '3', '27', '5', '27', '26',
'3', '5', '28', '3', '28', '5', '28', '3', '28', '19', '28', '26',
'37', '26', '37', '26', '37', '3', '37', '3', '26', '3', '26', '25',
'19', '37', '24', '3', '5', '3', '1', '5', '1', '3', '23', '37', '24',
'3', '24', '35', '23', '5', '3', '24', '3', '24', '1', '24', '3',
'24', '3', '5', '3', '5', '2', '25', '5', '3', '24', '25', '5', '25',
'3', '22', '3', '5', '3', '23', '3', '24', '3', '5', '3', '1', '5',
'22', '1', '24', '3', '24', '3', '5', '3', '5']

cList=['19', '14', '39', '15', '43', '19', '43', '15', '13', '17',
'14', '17', '43', '17', '1', '14', '2', '39', '1', '14', '39', '14',
'13', '19', '14', '19', '14', '19', '39', '22', '39', '1', '39', '22',
'39', '22', '39', '22', '39', '1', '17', '19', '39', '22', '14', '39',
'22', '39', '1', '19', '4', '22', '14', '19', '17', '14', '19', '4',
'22', '20', '1', '20', '22', '20', '1', '39', '1', '20', '38', '39',
'20', '39', '22', '39', '1', '39', '1', '38', '22', '38', '39', '19',
'14', '19', '3', '1', '3', '2', '3', '14', '3', '4', '14', '1', '14',
'1', '14', '66', '14', '22', '14', '2', '14', '1', '14', '39', '14',
'28', '14', '27', '19', '14', '29', '14', '21', '19', '43', '19',
'23', '45', '29', '1', '21', '28', '8', '50', '53', '58'

[Tutor] failed to load functions,

2011-11-11 Thread lina
Hi,

sorry for the new post:

if __name__=="__main__":

for i in range(97,100):
for j in range(97,100):
if i != j:
s1=chr(i)+"List"
s2=chr(j)+"List"
'''print(s1,s2)'''
LongestCommonSubstring(s1,s2)

I am surprised the results showed like below:

$ python3 CommonSubstring.py
Lis
List
Lis
List
Lis
List
Lis
List
Lis
List
Lis
List

and
print(s1,s2)
'''LongestCommonSubstring(s1,s2)'''
showed me:

aList bList
aList cList
bList aList
bList cList
cList aList
cList bList


exactly I wanted,

but seems s1, s2 failed to go into functions.

Thanks,
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] longest common substring

2011-11-11 Thread lina


I wrote a crazy one, to find the common group:

Please jump to the end part of this code:

https://docs.google.com/open?id=0B93SVRfpVVg3MDUzYzI1MDYtNmI5MS00MmZkLTlmMTctNmE3Y2EyYzIyZTk2

Thanks again,
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how can I save it from "for"

2011-11-11 Thread bodsda
Look into the 'continue' and 'break' statements - both very handy when working 
with loops

Or just increment/decrement the conditional until it evaluates to False

Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: lina 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Sat, 12 Nov 2011 00:41:43 
To: tutor
Subject: [Tutor] how can I save it from "for"

Hi, I don't know how to escape the

if longest >= 3:
subgroup=S1[x_longest-longest:x_longest]
print(subgroup)

form the loop.


xrange = range

subgroup=[]
def LongestCommonSubstring(S1, S2):
M = [[0]*(1+len(S2)) for i in xrange(1+len(S1))]
longest, x_longest = 0, 0
subgroups=[]
uniq={}
for x in xrange(1,1+len(S1)):
for y in xrange(1,1+len(S2)):
if S1[x-1] == S2[y-1]:
M[x][y] = M[x-1][y-1]+1
if M[x][y] > longest:
longest = M[x][y]
x_longest = x
else:
M[x][y] = 0
if longest >= 3:
subgroup=S1[x_longest-longest:x_longest]
print(subgroup)


return S1[x_longest-longest:x_longest]


if __name__=="__main__":

for i in range(97,107):
for j in range(97,107):
if i != j:
LongestCommonSubstring(a,b)
'''LongestCommonSubstring(chr(i),chr(j))'''

Thanks ahead,
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how can I save it from "for"

2011-11-11 Thread lina
Hi, I don't know how to escape the

if longest >= 3:
subgroup=S1[x_longest-longest:x_longest]
print(subgroup)

form the loop.


xrange = range

subgroup=[]
def LongestCommonSubstring(S1, S2):
M = [[0]*(1+len(S2)) for i in xrange(1+len(S1))]
longest, x_longest = 0, 0
subgroups=[]
uniq={}
for x in xrange(1,1+len(S1)):
for y in xrange(1,1+len(S2)):
if S1[x-1] == S2[y-1]:
M[x][y] = M[x-1][y-1]+1
if M[x][y] > longest:
longest = M[x][y]
x_longest = x
else:
M[x][y] = 0
if longest >= 3:
subgroup=S1[x_longest-longest:x_longest]
print(subgroup)


return S1[x_longest-longest:x_longest]


if __name__=="__main__":

for i in range(97,107):
for j in range(97,107):
if i != j:
LongestCommonSubstring(a,b)
'''LongestCommonSubstring(chr(i),chr(j))'''

Thanks ahead,
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Suggest Book

2011-11-11 Thread Alexander Etter
On Nov 11, 2011, at 9:29, Pankaj Jakhar  wrote:

> Hello
> 
> Please suggest me the best book for Python from which I can learn basics to 
> advanced Python.
> 
> Thank you.
> 
> PankaJ Jakhar
> 
I'm sure Alan or one of our veteran list members will have something to say, 
but at my school for a class called "intro to problem solving" or something 
like that CS1114, the book used is by T. Gaddis, "Introduction to Python". 
I think. I may be incorrect. I'll check it out on amazon. 
Alexander
> ___
> Tutor  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] longest common substring

2011-11-11 Thread Jerry Hill
There's nothing wrong with writing your own code to find the longest common
substring, but are you aware that python has a module in the standard
library that already does this?  In the difflib module, the SequenceMatcher
class can compare two sequences and extract the longest common sequence of
elements from it, like this:

Code:
import difflib

a = [1, 2, 3, 7]
b = [2, 3, 7]

seq_matcher = difflib.SequenceMatcher(None, a, b)
print seq_matcher.find_longest_match(0, len(a), 0, len(b))

Outputs:
Match(a=1, b=0, size=3)

See http://docs.python.org/library/difflib.html#sequencematcher-objects for
lots of details.  The SequenceMatcher class can do a lot more than finding
the common substrings, as you might expect.  The Module of the Week article
for difflib may also be of interest:
http://www.doughellmann.com/PyMOTW/difflib/index.html

-- 
Jerry
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] longest common substring

2011-11-11 Thread lina
On Fri, Nov 11, 2011 at 9:10 PM, Andreas Perstinger
 wrote:
> On 2011-11-11 05:14, lina wrote:
>>
>> def LongestCommonSubstring(S1, S2):
>>     M = [[0]*(1+len(S2)) for i in xrange(1+len(S1))] ## creat 4*5 matrix
>>     longest, x_longest = 0, 0
>>     for x in xrange(1,1+len(S1)):                 ## read each row
>>         for y in xrange(1,1+len(S2)):             ## read each coloumn
>>             if S1[x-1] == S2[y-1]:
>>                 M[x][y] = M[x-1][y-1]+1
>>                 if M[x][y]>  longest:
>>                     longest = M[x][y]
>>                     x_longest = x
>>                 else:
>>                     M[x][y] = 0
>>     return S1[x_longest-longest:x_longest]
>
> That's still not the right version.
>
> If you compare your version to the one at wikibooks (
> http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Longest_common_substring#Python
> ), you'll see that the else-branch is wrongly indented (one level too deep).
> It belongs to the first if-comparison:
>
> if S1 ...
>     M[x][y] ...
>     if M[x][y] ...
>        ...
> else: ...
>
>
>> if __name__=="__main__":
>>
>>     a=open("atom-pair_4.txt","r").readline().strip()
>>
>>     b=open("atom-pair_8.txt","r").readline().strip()
>>
>>
>> print(LongestCommonSubstring(LongestCommonSubstring(a,a),LongestCommonSubstring(b,b)))
>
>                                    ^^^
> ??? What do you try to accomplish here ???
> You call "LongestCommonSubstring" with identical strings, thus the result
> must be the same string.
> Why not
>
> print(LongestCommonSubstring(a, b))
>
> as you did the line below with "c" and "d"?
>
> Further more I think that your problems start with bad data files. In every
> file there is just one very long line which looks like a string
> representation of a list of two-digits strings. This complicates further
> processing because you have to deal with all the unnecessary commas, blanks
> and single quotes between your numbers and the square brackets at the
> beginning and the end of the line.
>
>
>>  $ python3 LongestCommonSubstring.py
>> 2189
>> ['
>> ['82']
>>
>> The results are wrong.
>> c, d are the string from file atom-pair_4,txt, exactly the same as a,
>> d is the same as b.
>>
>> and even for (c,d) results are not correct, visually we can see some
>> similar groups, not mention the longest groups.
>
> And even if you use the correct function from wikibooks I can anticipate
> another problem :-)
> The implementation from wikibooks just returns the first common substring
> which it finds in the first string:
>
 WikibooksLongestCommonSubstring("ABAB","BABA")
> 'ABA'
 WikibooksLongestCommonSubstring("BABA", "ABAB")
> 'BAB'
>
> If there are more possible substrings with the same length (as in the
> example above) only the first one is returned.
>
> But in your example there are at least two different pathways (I've found
> three) which have the same length, as changing the order of the parameters
> will show you:
>
 WikibooksLongestCommonSubstring(c, d)
> ['61', '70', '61']
 WikibooksLongestCommonSubstring(d, c)
> ['83', '61', '83']

The residues of WikibooksLongestCommonSubstring(d, c) and
WikibooksLongestCommonSubstring(c,d) is different very largely,

I mean, it might be totally different.

so the possible subgroups are the union of groups of (d,c) and (c,d)?

I am really lack a programed-brain to think.

Thanks again,

>
> Bye, Andreas
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Suggest Book

2011-11-11 Thread Troy S
I would recommend: Beginning Python: From Novice to Professional.
See attached URL below.  Website is also a good resource.

http://trizpug.org/up-to-speed

On Fri, Nov 11, 2011 at 9:29 AM, Pankaj Jakhar  wrote:
> Hello
>
> Please suggest me the best book for Python from which I can learn basics to
> advanced Python.
>
> Thank you.
> 
> PankaJ Jakhar
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>



-- 
Troy S
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Suggest Book

2011-11-11 Thread Pankaj Jakhar
Hello

Please suggest me the best book for Python from which I can learn basics to
advanced Python.

Thank you.
*
PankaJ **Jakhar**
*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] longest common substring

2011-11-11 Thread lina


Based on former advice, I made a correction/modification on the below code.

1] the set and subgroup does not work, here I wish to put all the
subgroup in a big set, the set like
$ python3 LongestCommonSubstring.py | uniq
{"1',"}
{"1', "}
{"1', '"}
{"1', '8"}
{"1', '82"}
{"1', '82'"}
{"1', '82',"}
{"1', '82', "}
{"1', '82', '"}
{"6', '61', '6"}
{"', '61', '63'"}
{"', '61', '63',"}
{"', '61', '63', "}
{"', '61', '63', '"}
{"', '61', '63', '6"}
{"', '61', '70', '61"}
{"', '61', '70', '61'"}
{"', '83', '61', '83',"}
{"', '83', '61', '83', "}
{"', '83', '61', '83', '"}

Please kindly notice I added a pipeline with uniq at the end, the true
prints were lots of replications, I don't know how to handle it in the
python code.

2] I still have trouble in reading files, mainly about not read "" etc.

Thanks with best regards,

#!/usr/bin/python3

import os.path

xrange = range

subgroups=[]
subgroup=[]
def LongestCommonSubstring(S1, S2):
M = [[0]*(1+len(S2)) for i in xrange(1+len(S1))]
longest, x_longest = 0, 0
for x in xrange(1,1+len(S1)):
for y in xrange(1,1+len(S2)):
if S1[x-1] == S2[y-1]:
M[x][y] = M[x-1][y-1]+1
if M[x][y] > longest:
longest = M[x][y]
x_longest = x
if longest >= 3:
subgroup=S1[x_longest-longest:x_longest]
subgroups=set([subgroup])
print(subgroups)
else:
M[x][y] = 0

return S1[x_longest-longest:x_longest]


if __name__=="__main__":

a=open("atom-pair_4.txt","r").readline().strip()

b=open("atom-pair_8.txt","r").readline().strip()

LongestCommonSubstring(a,b)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] positional output

2011-11-11 Thread Walter Prins
Hi Frankie,

On 11 November 2011 12:59, Cranky Frankie  wrote:

> I'm trying to build a script to parse IBM AIX DB2 DDL to line up the
> data types (it drives me crazy when the column data types are not
> lined up). For example, typical create table DDL might be hundreds of
> lines long but will look like this:
>

Just knocked this up:
http://pastie.org/2847380

It reformats the example you posted, at least, and should leave lines that
are not field definitions alone (thanks to looking for the start of the
datatype after the space.) Hopefully you can get some inspiration form it.

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] positional output

2011-11-11 Thread Hugo Arts
On Fri, Nov 11, 2011 at 1:59 PM, Cranky Frankie
 wrote:
> Thank you for your help on this. Now for "the rest of the story."
>
> I'm trying to build a script to parse IBM AIX DB2 DDL to line up the
> data types (it drives me crazy when the column data types are not
> lined up). For example, typical create table DDL might be hundreds of
> lines long but will look like this:
>
> --
> -- table create DDL
> --
> CREATE TABLE FRANK.TEST (
> COLUMN1     DECIMAL(8),
> COLUMN2           CHAR(20),
> COLUMN3                    TIMESTAMP,
> COLUMN4     INTEGER,
> COLUMN5          DATE NOT NULL WITH DEFAULT,
> -- repeat for hundreds of columns
> );
> COMMENT ON TABLE FRANK.TEST IS 'TEST TABLE';
>
> This is just a small sample, there are many other possible lines, but
> I'm only concerned about the column lines like COLUMN1 through COLUMN5
> above.
>
> I have a script on Windows that reads in the DDL file and writes out
> each line to a new file. What I'm doing is using the split() function
> to test for the presence of any DB2 standard data type, like CHAR,
> INTEGER, SMALINT, etc. If I find one I want to use positional output
> to make each like look like:
>
> COLUMN1                        DECIMAL(8),
> COLUMN2                        CHAR(20),
> COLUMN3                        TIMESTAMP,
> COLUMN4                         INTEGER,
> COLUMN5                         DATE NOT NULL WITH DEFAULT,
>
> where all the COLUMNs would be in column 1 of the output file, the
> data types would be in column 40, and the comma would be next.
>
> The problem is handling lines that have NOT NULL WITH DEFAULT at the
> end. The thing is there could be other valid DDL in that position, and
> there may or may not be a comma after the data type. What I want to do
> is just take anything after the datatype, which would be element(1) in
> the split() output, and just write it out. I thought I could use
> rsplit() to do this, but you can't put the output of split() in
> rsplit() - I tried.
>
> I need to do something like, after verifying that element(1) is a
> valid DB2 datatype, just take everything else on the line after it,
> which may be a single comma, or NOT NULL WITH DEFAULT, or something
> else, and place it on the output line to be written out.
>
> So, to reiterate: I'm trying to build a script to line up the data
> types in a create table DDL file. Splitting each line into individual
> space separated elements, then checking for a valid data type, the
> rebuilding the line positionally seems to be the way to go. If there's
> an easyier way to do it I'm all ears.
>
> I don't have my script available at the moment but I could send it if
> it would be helpful.
>

I would suggest using str.split(None, 1) to limit the amount of splits
done to only 1, which means you get a list like ['COLUMN', 'DATA TYPE
ETC'].

Then you use the str.startswith function to check the second entry for
data types, something like so (note startswith accepts a tuple of
strings to look for:

if splitted_line[1].startswith(data_types):
print "%s %s" % (splitted_line[0].ljust(39), splitted_line[1])

HTH,
Hugo
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] positional output

2011-11-11 Thread Christian Witts

On 2011/11/11 02:59 PM, Cranky Frankie wrote:

Thank you for your help on this. Now for "the rest of the story."

I'm trying to build a script to parse IBM AIX DB2 DDL to line up the
data types (it drives me crazy when the column data types are not
lined up). For example, typical create table DDL might be hundreds of
lines long but will look like this:




Something like this ? I left out checking for valid types etc, just 
something rudimentary to maybe point you in the right direction.



>>> a = """COLUMN1 DECIMAL(8),
... COLUMN2   CHAR(20),
... COLUMN3TIMESTAMP,
... COLUMN4 INTEGER,
... COLUMN5  DATE NOT NULL WITH DEFAULT,
... COLUMN6   CHAR(40)
... """
>>>
>>> for line in a.splitlines():
... newline = line.split()
... col_name = newline[0]
... col_type = newline[1].replace(',', '')
... field_sep = ',' if ',' in line else ''
... print '%-40s%s%s' % (col_name, col_type, field_sep)
...
COLUMN1 DECIMAL(8),
COLUMN2 CHAR(20),
COLUMN3 TIMESTAMP,
COLUMN4 INTEGER,
COLUMN5 DATE,
COLUMN6 CHAR(40)

If all you want to space it out nicely then .split(' ', 1) and '%-40s%s' 
% (part1, part2) should work fine for you.


--

Christian Witts
Python Developer

//
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] longest common substring

2011-11-11 Thread lina
On Fri, Nov 11, 2011 at 9:10 PM, Andreas Perstinger
 wrote:
> On 2011-11-11 05:14, lina wrote:
>>
>> def LongestCommonSubstring(S1, S2):
>>     M = [[0]*(1+len(S2)) for i in xrange(1+len(S1))] ## creat 4*5 matrix
>>     longest, x_longest = 0, 0
>>     for x in xrange(1,1+len(S1)):                 ## read each row
>>         for y in xrange(1,1+len(S2)):             ## read each coloumn
>>             if S1[x-1] == S2[y-1]:
>>                 M[x][y] = M[x-1][y-1]+1
>>                 if M[x][y]>  longest:
>>                     longest = M[x][y]
>>                     x_longest = x
>>                 else:
>>                     M[x][y] = 0
>>     return S1[x_longest-longest:x_longest]
>
> That's still not the right version.
>
> If you compare your version to the one at wikibooks (
> http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Longest_common_substring#Python
> ), you'll see that the else-branch is wrongly indented (one level too deep).
> It belongs to the first if-comparison:
>
> if S1 ...
>     M[x][y] ...
>     if M[x][y] ...
>        ...
> else: ...

Thanks, I was so careless and most important failure to give a deep
understanding.
>
>
>> if __name__=="__main__":
>>
>>     a=open("atom-pair_4.txt","r").readline().strip()
>>
>>     b=open("atom-pair_8.txt","r").readline().strip()
>>
>>
>> print(LongestCommonSubstring(LongestCommonSubstring(a,a),LongestCommonSubstring(b,b)))
>
>                                    ^^^
> ??? What do you try to accomplish here ???
> You call "LongestCommonSubstring" with identical strings, thus the result
> must be the same string.
Yes, the results is the same string,
actually I want to remove the distractions of "," and as you noticed,
the blanks and single quotes between numbers and the square brackets
at the two terminal of the line.
a=open("atom-pair_4.txt","r").readline().strip()
read so many unnecessary and I have a trouble of removing those distractions.

> Why not
>
> print(LongestCommonSubstring(a, b))
>
> as you did the line below with "c" and "d"?
>
> Further more I think that your problems start with bad data files. In every
> file there is just one very long line which looks like a string
> representation of a list of two-digits strings. This complicates further
> processing because you have to deal with all the unnecessary commas, blanks
> and single quotes between your numbers and the square brackets at the
> beginning and the end of the line.
>
>
>>  $ python3 LongestCommonSubstring.py
>> 2189
>> ['
>> ['82']
>>
>> The results are wrong.
>> c, d are the string from file atom-pair_4,txt, exactly the same as a,
>> d is the same as b.
>>
>> and even for (c,d) results are not correct, visually we can see some
>> similar groups, not mention the longest groups.
>
> And even if you use the correct function from wikibooks I can anticipate
> another problem :-)
> The implementation from wikibooks just returns the first common substring
> which it finds in the first string:
>
 WikibooksLongestCommonSubstring("ABAB","BABA")
> 'ABA'
 WikibooksLongestCommonSubstring("BABA", "ABAB")
> 'BAB'
>
> If there are more possible substrings with the same length (as in the
> example above) only the first one is returned.
You are right, I did not think of this parts before.

and actually the initiative wish was to find possible paths, I mean,
possible substrings, all possible substrings. not the longest one, but
at least bigger than 3.
>
> But in your example there are at least two different pathways (I've found
> three) which have the same length, as changing the order of the parameters
> will show you:
>
 WikibooksLongestCommonSubstring(c, d)
> ['61', '70', '61']
 WikibooksLongestCommonSubstring(d, c)
> ['83', '61', '83']
>
> Bye, Andreas

Thanks for your time,

Best regards,
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] longest common substring

2011-11-11 Thread Andreas Perstinger

On 2011-11-11 05:14, lina wrote:

def LongestCommonSubstring(S1, S2):
 M = [[0]*(1+len(S2)) for i in xrange(1+len(S1))] ## creat 4*5 matrix
 longest, x_longest = 0, 0
 for x in xrange(1,1+len(S1)): ## read each row
 for y in xrange(1,1+len(S2)): ## read each coloumn
 if S1[x-1] == S2[y-1]:
 M[x][y] = M[x-1][y-1]+1
 if M[x][y]>  longest:
 longest = M[x][y]
 x_longest = x
 else:
 M[x][y] = 0
 return S1[x_longest-longest:x_longest]


That's still not the right version.

If you compare your version to the one at wikibooks ( 
http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Longest_common_substring#Python 
), you'll see that the else-branch is wrongly indented (one level too 
deep). It belongs to the first if-comparison:


if S1 ...
 M[x][y] ...
 if M[x][y] ...
...
else: ...



if __name__=="__main__":

 a=open("atom-pair_4.txt","r").readline().strip()

 b=open("atom-pair_8.txt","r").readline().strip()

 
print(LongestCommonSubstring(LongestCommonSubstring(a,a),LongestCommonSubstring(b,b)))

^^^
??? What do you try to accomplish here ???
You call "LongestCommonSubstring" with identical strings, thus the 
result must be the same string.

Why not

print(LongestCommonSubstring(a, b))

as you did the line below with "c" and "d"?

Further more I think that your problems start with bad data files. In 
every file there is just one very long line which looks like a string 
representation of a list of two-digits strings. This complicates further 
processing because you have to deal with all the unnecessary commas, 
blanks and single quotes between your numbers and the square brackets at 
the beginning and the end of the line.




  $ python3 LongestCommonSubstring.py
2189
['
['82']

The results are wrong.
c, d are the string from file atom-pair_4,txt, exactly the same as a,
d is the same as b.

and even for (c,d) results are not correct, visually we can see some
similar groups, not mention the longest groups.


And even if you use the correct function from wikibooks I can anticipate 
another problem :-)
The implementation from wikibooks just returns the first common 
substring which it finds in the first string:


>>> WikibooksLongestCommonSubstring("ABAB","BABA")
'ABA'
>>> WikibooksLongestCommonSubstring("BABA", "ABAB")
'BAB'

If there are more possible substrings with the same length (as in the 
example above) only the first one is returned.


But in your example there are at least two different pathways (I've 
found three) which have the same length, as changing the order of the 
parameters will show you:


>>> WikibooksLongestCommonSubstring(c, d)
['61', '70', '61']
>>> WikibooksLongestCommonSubstring(d, c)
['83', '61', '83']

Bye, Andreas

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] positional output

2011-11-11 Thread Cranky Frankie
Thank you for your help on this. Now for "the rest of the story."

I'm trying to build a script to parse IBM AIX DB2 DDL to line up the
data types (it drives me crazy when the column data types are not
lined up). For example, typical create table DDL might be hundreds of
lines long but will look like this:

-- 
-- table create DDL
--
CREATE TABLE FRANK.TEST (
COLUMN1 DECIMAL(8),
COLUMN2   CHAR(20),
COLUMN3TIMESTAMP,
COLUMN4 INTEGER,
COLUMN5  DATE NOT NULL WITH DEFAULT,
-- repeat for hundreds of columns
);
COMMENT ON TABLE FRANK.TEST IS 'TEST TABLE';

This is just a small sample, there are many other possible lines, but
I'm only concerned about the column lines like COLUMN1 through COLUMN5
above.

I have a script on Windows that reads in the DDL file and writes out
each line to a new file. What I'm doing is using the split() function
to test for the presence of any DB2 standard data type, like CHAR,
INTEGER, SMALINT, etc. If I find one I want to use positional output
to make each like look like:

COLUMN1DECIMAL(8),
COLUMN2CHAR(20),
COLUMN3TIMESTAMP,
COLUMN4 INTEGER,
COLUMN5 DATE NOT NULL WITH DEFAULT,

where all the COLUMNs would be in column 1 of the output file, the
data types would be in column 40, and the comma would be next.

The problem is handling lines that have NOT NULL WITH DEFAULT at the
end. The thing is there could be other valid DDL in that position, and
there may or may not be a comma after the data type. What I want to do
is just take anything after the datatype, which would be element(1) in
the split() output, and just write it out. I thought I could use
rsplit() to do this, but you can't put the output of split() in
rsplit() - I tried.

I need to do something like, after verifying that element(1) is a
valid DB2 datatype, just take everything else on the line after it,
which may be a single comma, or NOT NULL WITH DEFAULT, or something
else, and place it on the output line to be written out.

So, to reiterate: I'm trying to build a script to line up the data
types in a create table DDL file. Splitting each line into individual
space separated elements, then checking for a valid data type, the
rebuilding the line positionally seems to be the way to go. If there's
an easyier way to do it I'm all ears.

I don't have my script available at the moment but I could send it if
it would be helpful.



-- 
Frank L. "Cranky Frankie" Palmeri, Guilderland, NY, USA
             Risible Riding Raconteur & Writer
Don't sweat the petty things, and don't pet the sweaty things.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Okay, this time I tried doing a little research but no luck in solving this one.

2011-11-11 Thread Christian Witts

On 2011/11/11 04:00 AM, Nathaniel Trujillo wrote:
Okay, I typed in python -c "import sys; print sys.version" at the 
command prompt. I didn't see a prompt ending with %. Instead I saw a 
prompt ending with >. But here is the message I got.

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
C:\Users\net2010>python -c "import sys; print sys.version"
'python' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\net2010>
Thanks for the help.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

R-Click on My Computer
-> Properties
-> Advanced
-> Environment Variables
-> Under "System Variables" find PATH, select it, and click Edit
-> Add your Python path to the end eg. c:\python27 (you will need to 
seperate it from all the other entries using a semi-colon, like 
c:\program files;c:\windows;c:\python27)

-> Click OK about 3 times till you've closed all the windows
-> Open a new Command Prompt and run python -c "import sys; print 
sys.version"


--

Christian Witts
Python Developer

//
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Okay, this time I tried doing a little research but no luck in solving this one.

2011-11-11 Thread Michael M Mason
On 11 November 2011 at 02:00 Nathaniel Trujillo wrote:-
> Okay, I typed in python -c "import sys; print sys.version" at the command
> prompt. I didn't see a prompt ending with %. Instead I saw a prompt ending
> with >. But here is the message I got.
> 
> Microsoft Windows [Version 6.1.7600]
> Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
> C:\Users\net2010>python -c "import sys; print sys.version"
> 'python' is not recognized as an internal or external command,
> operable program or batch file.
> C:\Users\net2010>

This is normal with Python on Windows. The Python installer doesn't add the 
program directory to the PATH, so you have to include the full pathname to run 
Python from  the command line, something like this:-

C:\Python27\python -c "import sys; print sys.version"

-- 
Michael

This mail was sent via Mail-SeCure System.



 
 

This footnote confirms that this email message has been scanned by
PineApp Mail-SeCure for the presence of malicious code, vandals & computer 
viruses.




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] The python implementation of the "class relationship".

2011-11-11 Thread Alan Gauld

On 11/11/11 02:39, Jerry Zhang wrote:


Composition implementation: you may need to do 5 job with C++, but only
2 job with python, the other 3 job is done by python implicitly.
association implementation: You need 3 job with C++, but 1 with python.
it seems python's object's lifecycle handling has reached this level,
all you should do is just "associating and de-association".


I have no idea what you mean by that.
What kind of "job" are you talking about?


Code_Zero. 1 job(by you) + 4(by python) does NOT work.
Code_one. 2 job(by you) + 3(by python) works. That is the best one.
Code_two. 3 job( by you) + 2 (by python) works too,
Code_three. 4 job(by you) + 1(by python) works too.

Since i am not familiar with python yet, my code most likely would gets
into Code_two or Code_three(Code_Zero is also possible for new guys like
me), though they also work, they are bad code.


Again, I don't understand your references to Code_one, Code_two etc?

--
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