Re: regular expression i'm going crazy

2011-05-16 Thread andy baxter
On 16/05/11 17:25, Tracubik wrote: pls help me fixing this: import re s = "linka la baba" re_s = re.compile(r'(link|l)a' , re.IGNORECASE) print re_s.findall(s) output: ['link', 'l'] why? i want my re_s to find linka and la, he just find link and l and forget about the ending a. The round br

Re: regular expression i'm going crazy

2011-05-16 Thread Alexander Kapps
On 16.05.2011 18:25, Tracubik wrote: pls help me fixing this: import re s = "linka la baba" re_s = re.compile(r'(link|l)a' , re.IGNORECASE) print re_s.findall(s) output: ['link', 'l'] why? As the docs say: "If one or more groups are present in the pattern, return a list of groups;" http

Re: regular expression i'm going crazy

2011-05-16 Thread Robert Kern
On 5/16/11 11:25 AM, Tracubik wrote: pls help me fixing this: import re s = "linka la baba" re_s = re.compile(r'(link|l)a' , re.IGNORECASE) print re_s.findall(s) output: ['link', 'l'] why? i want my re_s to find linka and la, he just find link and l and forget about the ending a. can anyone

regular expression i'm going crazy

2011-05-16 Thread Tracubik
pls help me fixing this: import re s = "linka la baba" re_s = re.compile(r'(link|l)a' , re.IGNORECASE) print re_s.findall(s) output: ['link', 'l'] why? i want my re_s to find linka and la, he just find link and l and forget about the ending a. can anyone help me? trying the regular expressio

Re: Brain going crazy with recursive functions

2008-12-07 Thread Lie Ryan
On Sat, 06 Dec 2008 23:33:35 -0800, 5lvqbwl02 wrote: > I'm trying to solve the 9-tile puzzle using as functional an approach as > possible. I've recently finished reading SICP and am deliberately > avoiding easy python-isms for the more convoluted scheme/functional > methods. The following funct

Re: Brain going crazy with recursive functions

2008-12-07 Thread Arnaud Delobelle
[EMAIL PROTECTED] writes: > I'm trying to solve the 9-tile puzzle using as functional an approach > as possible. I've recently finished reading SICP and am deliberately > avoiding easy python-isms for the more convoluted scheme/functional > methods. The following function is trivial to do with f

Re: Brain going crazy with recursive functions

2008-12-07 Thread James Stroud
James Stroud wrote: def linear_search(array, truth_func, loc=(0,0)): idx1, idx2 = loc if idx1 >= len(array): return None if idx2 >= len(array[idx1]): return linear_search(array, truth_func, (idx1+1, 0)) value = array[idx1][idx2] tf = truth_func(value) if tf: return loc e

Re: Brain going crazy with recursive functions

2008-12-07 Thread James Stroud
[EMAIL PROTECTED] wrote: I'm trying to solve the 9-tile puzzle using as functional an approach as possible. I've recently finished reading SICP and am deliberately avoiding easy python-isms for the more convoluted scheme/functional methods. The following function is trivial to do with for loops

Brain going crazy with recursive functions

2008-12-06 Thread 5lvqbwl02
I'm trying to solve the 9-tile puzzle using as functional an approach as possible. I've recently finished reading SICP and am deliberately avoiding easy python-isms for the more convoluted scheme/functional methods. The following function is trivial to do with for loops and directly accessing arr

Brain going crazy with recursive functions

2008-12-06 Thread 5lvqbwl02
I'm trying to solve the 9-tile puzzle using as functional an approach as possible. I've recently finished reading SICP and am deliberately avoiding easy python-isms for the more convoluted scheme/functional methods. The following function is trivial to do with for loops and directly accessing arr

Re: eval to dict problems NEWB going crazy !

2006-07-10 Thread Fredrik Lundh
Ant wrote: > So how do python app's typically embed python? For example things like > Zope and idle are scripted using Python - presumably they restrict the > execution of the scripts to a restricted set of modules/objects - but > how is this done? why? anyone capable of adding code to idle alre

Re: eval to dict problems NEWB going crazy !

2006-07-10 Thread Ant
> As Fredrik points out, embedded Python isn't the same as running > untrusted code. The reality is, Python has not been designed for running > untrusted code safely. So how do python app's typically embed python? For example things like Zope and idle are scripted using Python - presumably they r

Re: eval to dict problems NEWB going crazy !

2006-07-10 Thread Sion Arrowsmith
Fredrik Lundh <[EMAIL PROTECTED]> wrote: >Ant wrote: >> It seems that there must be a way to use eval safely, as there are >> plenty of apps that embed python as a scripting language - and what's >> the point of an eval function if impossible to use safely, and you have >> to write your own Python

Re: eval to dict problems NEWB going crazy !

2006-07-07 Thread Steven D'Aprano
On Fri, 07 Jul 2006 09:39:38 -0700, Ant wrote: > >> [('recId', 3), ('parse', {'pos': u'np', 'gen': u'm'})] >> [('recId', 5), ('parse', {'pos': u'np', 'gen': u'm'})] >> # line injected by a malicious user >> "__import__('os').system('echo if I were bad I could do worse')" >> [('recId', 7 ), ('pars

Re: eval to dict problems NEWB going crazy !

2006-07-07 Thread Steven D'Aprano
On Fri, 07 Jul 2006 19:57:02 +0200, Fredrik Lundh wrote: > Steven D'Aprano wrote: > >> Personally, I would never use eval on any string I didn't write myself. If >> I was thinking about evaluating a user-string, I would always write a >> function to parse the string and accept only the specific s

Re: eval to dict problems NEWB going crazy !

2006-07-07 Thread Fredrik Lundh
Steven D'Aprano wrote: > Personally, I would never use eval on any string I didn't write myself. If > I was thinking about evaluating a user-string, I would always write a > function to parse the string and accept only the specific sort of data I > expected. In your case, a quick-and-dirty unteste

Re: eval to dict problems NEWB going crazy !

2006-07-07 Thread Fredrik Lundh
Ant wrote: > It seems that there must be a way to use eval safely, as there are > plenty of apps that embed python as a scripting language - and what's > the point of an eval function if impossible to use safely, and you have > to write your own Python parser!! embedding python != accepting scrip

Re: eval to dict problems NEWB going crazy !

2006-07-07 Thread Ant
> [('recId', 3), ('parse', {'pos': u'np', 'gen': u'm'})] > [('recId', 5), ('parse', {'pos': u'np', 'gen': u'm'})] > # line injected by a malicious user > "__import__('os').system('echo if I were bad I could do worse')" > [('recId', 7 ), ('parse', {'pos': u'np', 'gen': u'm'})] I'm curious, if you

Re: eval to dict problems NEWB going crazy !

2006-07-07 Thread Steven D'Aprano
On Thu, 06 Jul 2006 03:34:32 -0700, manstey wrote: > Hi, > > I have a text file called a.txt: > > # comments > [('recId', 3), ('parse', {'pos': u'np', 'gen': u'm'})] > [('recId', 5), ('parse', {'pos': u'np', 'gen': u'm'})] > [('recId', 7 ), ('parse', {'pos': u'np', 'gen': u'm'})] > > I read it

Re: eval to dict problems NEWB going crazy !

2006-07-06 Thread Fredrik Lundh
> hint 1: hint 1b: >>> eval("[('recId', 3), ('parse', {'pos': u'np', 'gen': u'm'})]") [('recId', 3), ('parse', {'pos': u'np', 'gen': u'm'})] >>> eval("[('recId', 3), ('parse', {'pos': u'np', 'gen': u'm'})]\n") [('recId', 3), ('parse', {'pos': u'np', 'gen': u'm'})] >>> eval("[('recId', 3), ('parse

Re: eval to dict problems NEWB going crazy !

2006-07-06 Thread Roel Schroeven
manstey schreef: > Hi, > > I have a text file called a.txt: > > # comments > [('recId', 3), ('parse', {'pos': u'np', 'gen': u'm'})] > [('recId', 5), ('parse', {'pos': u'np', 'gen': u'm'})] > [('recId', 7 ), ('parse', {'pos': u'np', 'gen': u'm'})] > > I read it using this: > > filAnsMorph = code

Re: eval to dict problems NEWB going crazy !

2006-07-06 Thread Fredrik Lundh
"manstey" <[EMAIL PROTECTED]> wrote: > That doesn't work. I just get an error: > >x = eval(line.strip('\n')) > File "", line 1 > [('recId', 3), ('parse', {'pos': u'np', 'gen': u'm'})] > > SyntaxError: unexpected EOF while parsing > > any other ideas? hint 1: >>> eval("[('recId', 3), ('p

Re: eval to dict problems NEWB going crazy !

2006-07-06 Thread Eric Deveaud
manstey wrote: > That doesn't work. I just get an error: > > x = eval(line.strip('\n')) >File "", line 1 > [('recId', 3), ('parse', {'pos': u'np', 'gen': u'm'})] > > SyntaxError: unexpected EOF while parsing > is the last line of your file empty ?? what with for line in filA

Re: eval to dict problems NEWB going crazy !

2006-07-06 Thread manstey
That doesn't work. I just get an error: x = eval(line.strip('\n')) File "", line 1 [('recId', 3), ('parse', {'pos': u'np', 'gen': u'm'})] SyntaxError: unexpected EOF while parsing any other ideas? Bruno Desthuilliers wrote: > manstey wrote: > > Hi, > > > > I have a text file called

Re: eval to dict problems NEWB going crazy !

2006-07-06 Thread Bruno Desthuilliers
manstey wrote: > Hi, > > I have a text file called a.txt: > > # comments > [('recId', 3), ('parse', {'pos': u'np', 'gen': u'm'})] > [('recId', 5), ('parse', {'pos': u'np', 'gen': u'm'})] > [('recId', 7 ), ('parse', {'pos': u'np', 'gen': u'm'})] > > I read it using this: > > filAnsMorph = codecs

eval to dict problems NEWB going crazy !

2006-07-06 Thread manstey
Hi, I have a text file called a.txt: # comments [('recId', 3), ('parse', {'pos': u'np', 'gen': u'm'})] [('recId', 5), ('parse', {'pos': u'np', 'gen': u'm'})] [('recId', 7 ), ('parse', {'pos': u'np', 'gen': u'm'})] I read it using this: filAnsMorph = codecs.open('a.txt', 'r', 'utf-8') # Initiali

Re: Going crazy...

2005-06-14 Thread Scott David Daniels
Jan Danielsson wrote: > Gary Herron wrote: >>... a more recent addition to the language is Sets, ... >from sets import Set >Set([1,2,3,4,5,6]) - Set([2,3,6]) >> >>Set([1, 4, 5]) If you are using 2.4 or later, you can simply use "set" without importing anything. set(['apple', 'orange'

Re: Going crazy...

2005-06-14 Thread Jan Danielsson
Gary Herron wrote: [---] >> I just tried typing the above in Python, and it - obviously - doesn't >> work, so it must be some other syntax. >> >> > Not with tuples, lists or dictionaries. However a more recent addition > to the language is Sets, and they support set differences: > from s

Re: Going crazy...

2005-06-13 Thread Irmen de Jong
Jan Danielsson wrote: > Hello all, > >I'm 100% sure that I saw an example which looked something like this > recently: > > a=(1, 2, 3, 4, 5, 6) b=(2, 3, 6) a - b > > (1, 4, 5) > >The only new language I have been involved in lately is Python. Is my > memory failing me, or h

Re: Going crazy...

2005-06-13 Thread Chinook
On Mon, 13 Jun 2005 20:52:43 -0400, Gary Herron wrote (in article <[EMAIL PROTECTED]>): > Jan Danielsson wrote: > >> Hello all, >> >> I'm 100% sure that I saw an example which looked something like this >> recently: >> >> >> > a=(1, 2, 3, 4, 5, 6) > b=(2, 3, 6) > a - b >

Re: Going crazy...

2005-06-13 Thread Gary Herron
Jan Danielsson wrote: >Hello all, > > I'm 100% sure that I saw an example which looked something like this >recently: > > > a=(1, 2, 3, 4, 5, 6) b=(2, 3, 6) a - b >(1, 4, 5) > > The only new language I have been involved in lately is Python. Is my >memory failin

Going crazy...

2005-06-13 Thread Jan Danielsson
Hello all, I'm 100% sure that I saw an example which looked something like this recently: >>> a=(1, 2, 3, 4, 5, 6) >>> b=(2, 3, 6) >>> a - b (1, 4, 5) The only new language I have been involved in lately is Python. Is my memory failing me, or have I seen such an Python-example somewhere? I