Python 3.10.0a6 is available, now with 100% more pattern matching

2021-03-02 Thread Pablo Galindo Salgado
Remember us? It's your friendly CPython release team and we have something we think you may like: The new alpha release of Python 3.10 is here, now with 100% more pattern matching. If I were you, I would download it and start playing with it. Extra points if you report us any bugs you find

[RELEASE] Python 3.10.0a6 is available, now with 100% more pattern matching

2021-03-02 Thread Pablo Galindo Salgado
Remember us? It's your friendly CPython release team and we have something we think you may like: The new alpha release of Python 3.10 is here, now with 100% more pattern matching. If I were you, I would download it and start playing with it. Extra points if you report us any bugs you find

Python Guarded Pattern matching (when x -> do action)

2016-11-15 Thread ygutfreund
I am looking to see if there is prior work, or design ideas for implementing pattern-matched guard statements in a very natural format for python programmers. For those not familiar with pattern matching in [SCALA][1], [Erlang][2], or [F#][3] They all have constructs similiar to: When

Re: re.search - Pattern matching review

2016-06-01 Thread Ganesh Pal
Thanks works fine : ) -- https://mail.python.org/mailman/listinfo/python-list

Re: re.search - Pattern matching review

2016-05-30 Thread Matt Wheeler
On 30 May 2016 at 10:03, Ganesh Pal wrote: > Thanks Matt for the reply and lovely analysis . I was trying to complicate > the simple task :( > > Here is how the code looks now , the whole idea was just to match the > pattern and return it > > > def get_block(block): > > cmd = "get_block_info

Re: re.search - Pattern matching review

2016-05-30 Thread Ganesh Pal
On Sun, May 29, 2016 at 10:32 PM, Matt Wheeler wrote: > > > This doesn't seem to exactly match your code below, i.e. your code is > attempting to construct a tuple from groups 1 through 4. To meet this > specification I could just `return re.search('(?<=\(block > )[^(]*(?=\))', stdout).group()` >

Re: re.search - Pattern matching review

2016-05-29 Thread Matt Wheeler
On 28 May 2016 at 19:12, Ganesh Pal wrote: > Dear Python friends, > > I am on Python 2.7 and Linux . I am trying to extract the address > "1,5,147456:8192" from the below stdout using re.search > > (Pdb) stdout > 'linux-host-machine-1: Block Address for 1,5,27320320:8192 (block > 1,5,147456:8192)

Re: re.search - Pattern matching review ( Apologies re sending)

2016-05-29 Thread Ganesh Pal
The matched.groups() will group the pattern based with "," (Pdb) matched.groups() *('1', '0', '1375772672', '8192')* but I wanted to retain the output as *'1,0,1375772672:8192' ,* (Pdb) matched.groups() ('1', '0', '1375772672', '8192') (Pdb) matched.group() 'Block Address for 1,0,1376034816:81

Re: re.search - Pattern matching review ( Apologies re sending)

2016-05-28 Thread Ganesh Pal
> Perhaps: > map(int, re.search(search_pat, stdout).groups()) > > > Thanks Albert map saved me many lines of code but map returns a list I will have to convert the list to string again Below is how Iam planning to teh conversion >>> block = map(int, re.search(search_pat, stdout).groups()) >>> p

RE: re.search - Pattern matching review ( Apologies re sending)

2016-05-28 Thread Albert-Jan Roskam
> Date: Sat, 28 May 2016 23:48:16 +0530 > Subject: re.search - Pattern matching review ( Apologies re sending) > From: ganesh1...@gmail.com > To: python-list@python.org > > Dear Python friends, > > I am on Python 2.7 and Linux . I am trying to extract the address >

re.search - Pattern matching review ( Apologies re sending)

2016-05-28 Thread Ganesh Pal
Dear Python friends, I am on Python 2.7 and Linux . I am trying to extract the address "1,5,147456:8192" from the below stdout using re.search (Pdb) stdout 'linux-host-machine-1: Block Address for 1,5,27320320:8192 (block 1,5,147456:8192) --\nlinux-host-machine-1: magic 0xdeaff2fe mark_c

re.search - Pattern matching review

2016-05-28 Thread Ganesh Pal
Dear Python friends, I am on Python 2.7 and Linux . I am trying to extract the address "1,5,147456:8192" from the below stdout using re.search (Pdb) stdout 'linux-host-machine-1: Block Address for 1,5,27320320:8192 (block 1,5,147456:8192) --\nlinux-host-machine-1: magic 0xdeaff2fe mark_c

Re: pattern matching

2011-02-24 Thread Jon Clements
On Feb 24, 2:11 am, monkeys paw wrote: > if I have a string such as '01/12/2011' and i want > to reformat it as '20110112', how do i pull out the components > of the string and reformat them into a DDMM format? > > I have: > > import re > > test = re.compile('\d\d\/') > f = open('test.html')  

Re: pattern matching

2011-02-24 Thread John S
On Feb 23, 9:11 pm, monkeys paw wrote: > if I have a string such as '01/12/2011' and i want > to reformat it as '20110112', how do i pull out the components > of the string and reformat them into a DDMM format? > > I have: > > import re > > test = re.compile('\d\d\/') > f = open('test.html')  

Re: pattern matching

2011-02-23 Thread Dr Vangel
if I have a string such as '01/12/2011' and i want to reformat it as '20110112', how do i pull out the components of the string and reformat them into a DDMM format? I have: import re test = re.compile('dd/') f = open('test.html') # This file contains the html dates for line in f: if

Re: pattern matching

2011-02-23 Thread Roy Smith
by my previous statement, however. If you're trying to parse HTML, use an HTML parser. Using a regex like this is perfectly fine for parsing the CDATA text inside the HTML element, but pattern matching the HTML markup itself is madness. -- http://mail.python.org/mailman/listinfo/python-list

Re: pattern matching

2011-02-23 Thread Chris Rebert
On Wed, Feb 23, 2011 at 6:37 PM, Steven D'Aprano wrote: > On Wed, 23 Feb 2011 21:11:53 -0500, monkeys paw wrote: >> if I have a string such as '01/12/2011' and i want to reformat >> it as '20110112', how do i pull out the components of the string and >> reformat them into a DDMM format? > > da

Re: pattern matching

2011-02-23 Thread Steven D'Aprano
On Wed, 23 Feb 2011 21:11:53 -0500, monkeys paw wrote: > if I have a string such as '01/12/2011' and i want to reformat > it as '20110112', how do i pull out the components of the string and > reformat them into a DDMM format? data = '01/12/2011' # Throw away tags. data = data[4:-5] # Separat

Re: pattern matching

2011-02-23 Thread Roy Smith
In article , monkeys paw wrote: > if I have a string such as '01/12/2011' and i want > to reformat it as '20110112', how do i pull out the components > of the string and reformat them into a DDMM format? > > I have: > > import re > > test = re.compile('\d\d\/') > f = open('test.html') #

pattern matching

2011-02-23 Thread monkeys paw
if I have a string such as '01/12/2011' and i want to reformat it as '20110112', how do i pull out the components of the string and reformat them into a DDMM format? I have: import re test = re.compile('\d\d\/') f = open('test.html') # This file contains the html dates for line in f:

Re: Help regarding pattern matching

2010-12-15 Thread Katie T
On Thu, Dec 16, 2010 at 2:34 AM, Chris Rebert wrote: > On Wed, Dec 15, 2010 at 6:22 PM, Katie T wrote: >> On Wed, Dec 15, 2010 at 9:21 PM, jupiter wrote: >>> Hi People, >>> >>> I need some ideas on how to find pattern in random data series like stock >>> chart. >>> >>> What I want is to be able

Re: Help regarding pattern matching

2010-12-15 Thread Chris Rebert
On Wed, Dec 15, 2010 at 6:22 PM, Katie T wrote: > On Wed, Dec 15, 2010 at 9:21 PM, jupiter wrote: >> Hi People, >> >> I need some ideas on how to find pattern in random data series like stock >> chart. >> >> What I want is to be able to find Head & Shoulder pattern in chart. > > Have a look at t

Re: Help regarding pattern matching

2010-12-15 Thread Katie T
On Wed, Dec 15, 2010 at 9:21 PM, jupiter wrote: > Hi People, > > > I need some ideas on how to find pattern in random data series like stock > chart. > > > What I want is to be able to find Head & Shoulder pattern in chart. Have a look at the references in: http://www.dpem.tuc.gr/fel/fm2009/Pap

Help regarding pattern matching

2010-12-15 Thread jupiter
Hi People, I need some ideas on how to find pattern in random data series like stock chart. What I want is to be able to find Head & Shoulder pattern in chart. Thanx Anil -- http://mail.python.org/mailman/listinfo/python-list

Re: pattern matching with multiple lists

2010-07-16 Thread Tim Chase
On 07/16/2010 02:20 PM, Chad Kellerman wrote: Greetings, I have some code that I wrote and know there is a better way to write it. I wonder if anyone could point me in the right direction on making this 'cleaner'. I have two lists: liveHostList = [ app11, app12, web11, web12, hos

Re: pattern matching with multiple lists

2010-07-16 Thread MRAB
Chad Kellerman wrote: Greetings, I have some code that I wrote and know there is a better way to write it. I wonder if anyone could point me in the right direction on making this 'cleaner'. I have two lists: liveHostList = [ app11, app12, web11, web12, host11 ]

pattern matching with multiple lists

2010-07-16 Thread Chad Kellerman
Greetings, I have some code that I wrote and know there is a better way to write it.  I wonder if anyone could point me in the right direction on making this 'cleaner'. I have two lists:   liveHostList = [ app11, app12, web11, web12, host11 ]     stageHos

Re: How to implement Varient/Tagged Unions/Pattern Matching in Python?

2009-12-12 Thread Kay Schluehr
> BTW, Please don't ask "Why do you want to do like this" No, I don't ask although it would be the interesting aspect for me ;) -- http://mail.python.org/mailman/listinfo/python-list

Re: How to implement Varient/Tagged Unions/Pattern Matching in Python?

2009-12-11 Thread Aahz
In article <358b227c-d836-4243-b79a-57258590a...@a10g2000pre.googlegroups.com>, metal wrote: > >I want to get pattern matching like OCaml in python(ref:http:// >en.wikipedia.org/wiki/Tagged_union) > >I consider the syntax: > >def decl(): > def Plus(expr, expr

How to implement Varient/Tagged Unions/Pattern Matching in Python?

2009-12-02 Thread metal
I want to get pattern matching like OCaml in python(ref:http:// en.wikipedia.org/wiki/Tagged_union) I consider the syntax: def decl(): def Plus(expr, expr): pass def Minus(expr, expr): pass def Times(expr, expr): pass def Divide(expr, expr): pass def Value

Re: python list pattern matching?

2009-05-29 Thread Terry Reedy
Peter Otten wrote: Terry Reedy wrote: >>> a,b,*rest = list(range(10)) The list() call is superfluous. Agreed, even in Py3 when range() returns a range object rather than a list. -- http://mail.python.org/mailman/listinfo/python-list

Re: python list pattern matching?

2009-05-29 Thread Chris Rebert
On Thu, May 28, 2009 at 3:57 PM, Terry Reedy wrote: > guthrie wrote: >> >> I want to do a functional like pattern match to get teh first two >> elements, and then the rest of an array return value. >> >> For example, assume that perms(x) returns a list of values, and I want >> to do this: >>    se

Re: python list pattern matching?

2009-05-28 Thread Peter Otten
Terry Reedy wrote: > >>> a,b,*rest = list(range(10)) The list() call is superfluous. -- http://mail.python.org/mailman/listinfo/python-list

Re: python list pattern matching?

2009-05-28 Thread guthrie
Many thanks to all; perfect solution! -- http://mail.python.org/mailman/listinfo/python-list

Re: python list pattern matching?

2009-05-28 Thread Steven D'Aprano
On Thu, 28 May 2009 18:57:42 -0400, Terry Reedy wrote: > >>> a,b,*rest = list(range(10)) That fails in Python 2.5 and 2.6. >>> a,b,*rest = list(range(10)) File "", line 1 a,b,*rest = list(range(10)) ^ SyntaxError: invalid syntax -- Steven -- http://mail.python.org/mailman/li

Re: python list pattern matching?

2009-05-28 Thread bearophileHUGS
Terry Reedy: >  >>> a,b,*rest = list(range(10)) >  >>> a,b,rest > (0, 1, [2, 3, 4, 5, 6, 7, 8, 9]) >  >>> a,*rest,b = 'abcdefgh' >  >>> a,rest,b > ('a', ['b', 'c', 'd', 'e', 'f', 'g'], 'h') For the next few years I generally suggest to specify the Python version too (if it's 2.x or 3.x). This is P

Re: python list pattern matching?

2009-05-28 Thread Mensanator
On May 28, 5:43 pm, guthrie wrote: > I want to do a functional like pattern match to get teh first two > elements, and then the rest of an array return value. > > For example, assume that perms(x) returns a list of values, and I want > to do this: >     seq=perms(x) > >     a = seq[0] >     b = se

Re: python list pattern matching?

2009-05-28 Thread Terry Reedy
guthrie wrote: I want to do a functional like pattern match to get teh first two elements, and then the rest of an array return value. For example, assume that perms(x) returns a list of values, and I want to do this: seq=perms(x) a = seq[0] b = seq[1] rest = seq[2:] Of course I

python list pattern matching?

2009-05-28 Thread guthrie
I want to do a functional like pattern match to get teh first two elements, and then the rest of an array return value. For example, assume that perms(x) returns a list of values, and I want to do this: seq=perms(x) a = seq[0] b = seq[1] rest = seq[2:] Of course I can shorten to:

Re: Pattern Matching Over Python Lists

2008-06-22 Thread eliben
> Fair enough. To help you understand the method I used, I'll give you > this hint. It's true that regex on works on strings. However, is there > any way to convert arbitrarily complex data structures to string > representations? You don't need to be an experienced Python user to > answer to this ;

Re: Pattern Matching Over Python Lists

2008-06-22 Thread Chris
something like: > > > > Another solution is to use a better (different) language, that has > > > built-in pattern matching, or allows to create one. > > > > Bye, > > > bearophile > > > Btw, Python's stdlib includes a regular expression lib

Re: Pattern Matching Over Python Lists

2008-06-20 Thread MRAB
On Jun 20, 1:45 am, Chris <[EMAIL PROTECTED]> wrote: > On Jun 17, 1:09 pm, [EMAIL PROTECTED] wrote: > > > Kirk Strauser: > > > > Hint: recursion.  Your general algorithm will be something like: > > > Another solution is to use a better (different) language,

Re: Pattern Matching Over Python Lists

2008-06-19 Thread Paddy
On Jun 20, 1:44 am, Chris <[EMAIL PROTECTED]> wrote: > Thanks for your help. Those weren't quite what I was looking for, but > I ended up figuring it out on my own. Turns out you can actually > search nested Python lists using simple regular expressions. Strange? How do you match nested '[' ... ']

Re: Pattern Matching Over Python Lists

2008-06-19 Thread John Machin
On Jun 20, 10:45 am, Chris <[EMAIL PROTECTED]> wrote: > On Jun 17, 1:09 pm, [EMAIL PROTECTED] wrote: > > > Kirk Strauser: > > > > Hint: recursion. Your general algorithm will be something like: > > > Another solution is to use a better (different) language,

Re: Pattern Matching Over Python Lists

2008-06-19 Thread Chris
On Jun 17, 1:09 pm, [EMAIL PROTECTED] wrote: > Kirk Strauser: > > > Hint: recursion. Your general algorithm will be something like: > > Another solution is to use a better (different) language, that has > built-in pattern matching, or allows to create one. > > Bye,

Re: Pattern Matching Over Python Lists

2008-06-19 Thread Chris
Thanks for your help. Those weren't quite what I was looking for, but I ended up figuring it out on my own. Turns out you can actually search nested Python lists using simple regular expressions. -- http://mail.python.org/mailman/listinfo/python-list

Re: Pattern Matching Over Python Lists

2008-06-17 Thread bearophileHUGS
Kirk Strauser: > Hint: recursion. Your general algorithm will be something like: Another solution is to use a better (different) language, that has built-in pattern matching, or allows to create one. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Pattern Matching Over Python Lists

2008-06-17 Thread Kirk Strauser
At 2008-06-17T05:55:52Z, Chris <[EMAIL PROTECTED]> writes: > Is anyone aware of any prior work done with searching or matching a > pattern over nested Python lists? I have this problem where I have a > list like: > > [1, 2, [1, 2, [1, 7], 9, 9], 10] > > and I'd like to search for the pattern [1, 2

Pattern Matching Over Python Lists

2008-06-16 Thread Chris
Is anyone aware of any prior work done with searching or matching a pattern over nested Python lists? I have this problem where I have a list like: [1, 2, [1, 2, [1, 7], 9, 9], 10] and I'd like to search for the pattern [1, 2, ANY] so that is returns: [1, 2, [1, 2, [6, 7], 9, 9], 10] [1, 2, [6,

Re: Tips Re Pattern Matching / REGEX

2008-03-27 Thread Miki
ry to do this with regex pattern > matching. > > Would someone be able to provide pointers regarding how do I approach > this? Any code samples would be greatly appreciated. The ultimate tool for handling HTML is http://www.crummy.com/software/BeautifulSoup/ where you can do stuff like: soup

Tips Re Pattern Matching / REGEX

2008-03-27 Thread egonslokar
with regex pattern matching. Would someone be able to provide pointers regarding how do I approach this? Any code samples would be greatly appreciated. Thanks. Sam \\ there are hundreds of thousands of items \\Item1 123 Text1: What do I do with these lines That span several rows

Re: pattern matching

2007-03-01 Thread Diez B. Roggisch
azrael wrote: > can someone give me good links for pattern matching in images using > python There is a python-binding available for the OpenCV library, a collection of state-of-the-art CV algorithms. And it comes with a free manual Diez -- http://mail.python.org/mailman/listinfo/

pattern matching

2007-03-01 Thread azrael
can someone give me good links for pattern matching in images using python -- http://mail.python.org/mailman/listinfo/python-list

Re: String Pattern Matching: regex and Python regex documentation

2006-09-26 Thread Ilias Lazaridis
Steve Holden wrote: > Xah Lee wrote: ... > > This project was undertaken as a response to a challenge put forth to > > me with a $100 reward, on 2005-04-12 on comp.lang.python newsgroup. I > > never received the due reward. > > > Your reading skills must be terrible. You never received the reward >

Re: String Pattern Matching: regex and Python regex documentation

2006-09-24 Thread Steve Holden
Xah Lee wrote: > Xah Lee wrote: > « the Python regex documentation is available at: > http://xahlee.org/perl-python/python_re-write/lib/module-re.html ...» > > Jürgen Exner wrote: > «Yeah, sure, and the Perl regex documentation is available at 'perldoc > perlre'. So what? Is that anything new or

Re: String Pattern Matching: regex and Python regex documentation

2006-09-24 Thread Xah Lee
Xah Lee wrote: « the Python regex documentation is available at: http://xahlee.org/perl-python/python_re-write/lib/module-re.html ...» Jürgen Exner wrote: «Yeah, sure, and the Perl regex documentation is available at 'perldoc perlre'. So what? Is that anything new or surprising?» It is of inter

Re: String Pattern Matching: regex and Python regex documentation

2006-09-22 Thread J�rgen Exner
Ilias Lazaridis wrote: > Xah Lee wrote: >> the Python regex documentation is available at: >> http://xahlee.org/perl-python/python_re-write/lib/module-re.html Yeah, sure, and the Perl regex documentation is available at 'perldoc perlre'. So what? Is that anything new or surprising? jue -- ht

Re: String Pattern Matching: regex and Python regex documentation

2006-09-22 Thread John Machin
Paul McGuire wrote: > "Steve Holden" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > > > > Ilias Lazardis meets Xah Lee. I just *know* we're in for trouble now ... > > > > regards > > Steve > > A sign of the End Times, perhaps? > Indeed. Armageddon outa here ;-) -- http://

Re: String Pattern Matching: regex and Python regex documentation

2006-09-22 Thread Paul McGuire
"Steve Holden" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Ilias Lazardis meets Xah Lee. I just *know* we're in for trouble now ... > > regards > Steve A sign of the End Times, perhaps? -- Paul -- http://mail.python.org/mailman/listinfo/python-list

Re: String Pattern Matching: regex and Python regex documentation

2006-09-22 Thread Steve Holden
Ilias Lazaridis wrote: > [followup to c.l.py] > > Xah Lee wrote: > >>the Python regex documentation is available at: >>http://xahlee.org/perl-python/python_re-write/lib/module-re.html >> >>Note that, i've just made the terms of use clear. >> >>Also, can anyone answer what is the precise terms of

Re: String Pattern Matching: regex and Python regex documentation

2006-09-22 Thread Ilias Lazaridis
[followup to c.l.py] Xah Lee wrote: > the Python regex documentation is available at: > http://xahlee.org/perl-python/python_re-write/lib/module-re.html > > Note that, i've just made the terms of use clear. > > Also, can anyone answer what is the precise terms of license of the > official python

String Pattern Matching: regex and Python regex documentation

2006-09-17 Thread Xah Lee
e: • Scsh manual, Chapter 6: Pattern-matching strings with regular expressions http://www.scsh.net/docu/html/man-Z-H-7.html • Mathematica Book, section 2.8.4 String Patterns http://documents.wolfram.com/mathematica/book/section-2.8.4 Xah [EMAIL PROTECTED] ∑ http://xahlee.org/ -- http://mail.

Re: String pattern matching

2006-04-16 Thread Jim Lewis
>You can do this with a regular expression... I tried the plain RE approach and found it no faster than my direct-coded version. Anyone have any ideas on how to code this problem elegantly without RE? My code is long and cumbersome - 200 lines! Speed is my primary concern but low LOC would be nice

Re: String pattern matching

2006-04-05 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > Thanks to all for the various good approaches. Kent's plain RE approach > seems the most straightforward - did not know that RE can handle this > situation - good to know! Thanks to Eddie Corns also who showed how to express the problem as a parsing problem. I am also

Re: String pattern matching

2006-04-05 Thread jimlewis
Thanks to all for the various good approaches. Kent's plain RE approach seems the most straightforward - did not know that RE can handle this situation - good to know! -- http://mail.python.org/mailman/listinfo/python-list

Re: String pattern matching

2006-04-03 Thread Eddie Corns
Kent Johnson <[EMAIL PROTECTED]> writes: >Eddie Corns wrote: >> If I get time I'll try to get this working in Sam Wilmott's Python pattern >> matching library. >> >> What fun! >Cool! I have to get in on the fun :-) >This program uses Sa

Re: String pattern matching

2006-04-03 Thread Kent Johnson
Jim Lewis wrote: > Anyone have experience with string pattern matching? > I need a fast way to match variables to strings. Example: > > string - variables > > abcaaab - xyz > abca - xy > eeabcac - vxw > > x matches abc > y matches a > z mat

Re: String pattern matching

2006-04-03 Thread Kent Johnson
Eddie Corns wrote: > Off topic I know but I've been learning snobol pattern matching recently so I > thought I'd give this one a bash. Here is my effort: > > define('foo(str)') > &fullscan = 1 > '/abcaaab/abca/

Re: String pattern matching

2006-04-03 Thread Eddie Corns
"Jim Lewis" <[EMAIL PROTECTED]> writes: >Anyone have experience with string pattern matching? >I need a fast way to match variables to strings. Example: >string - variables > >abcaaab - xyz >abca - xy >eeabcac - vxw >x matches abc >y matc

Re: String pattern matching

2006-04-02 Thread Jim Lewis
Thanks for the interesting and detailed analysis. In my case I don't need all possible answers by rather the first "greedy" match. Seems like there might be some recursive approach. -- http://mail.python.org/mailman/listinfo/python-list

Re: String pattern matching

2006-04-01 Thread forward
Firstly sort variable expressions by its length xy = 'abca' xyz = 'abcaaab' vxw = 'eeabcac' Expand all expressions by its values except itself xy = 'abca' 'abca' z = 'abcaaab' vxw = 'eeabcac' Cut all left and right matches xy = 'abca' z = 'aab' vxw = 'eeabcac' Repeat until you

String pattern matching

2006-04-01 Thread Jim Lewis
Anyone have experience with string pattern matching? I need a fast way to match variables to strings. Example: string - variables abcaaab - xyz abca - xy eeabcac - vxw x matches abc y matches a z matches aab w maches ac v maches ee -- http://mail.python.org/mailman/listinfo/python

Re: Pattern matching with string and list

2005-12-13 Thread Brett g Porter
BartlebyScrivener wrote: > Even without the marker, can't you do: > > sentence = "the fabric is red" > colors = ["red", "white", "blue"] > > for color in colors: > if (sentence.find(color) > 0): > print color, sentence.find(color) > That depends on whether you're only looking for who

Re: Pattern matching with string and list

2005-12-13 Thread BartlebyScrivener
Even without the marker, can't you do: sentence = "the fabric is red" colors = ["red", "white", "blue"] for color in colors: if (sentence.find(color) > 0): print color, sentence.find(color) -- http://mail.python.org/mailman/listinfo/python-list

Re: Pattern matching with string and list

2005-12-13 Thread BartlebyScrivener
Taking you literally, I'm not sure you need regex. If you know or can find position n, then can't you just: sentence = "the color is $red" patterns = ["blue","red","yellow"] pos = sentence.find("$") for x in patterns: if x==sentence[pos+1:]: print x, pos+1 But maybe I'm oversimplifyin

Re: Pattern matching with string and list

2005-12-12 Thread Tom Anderson
On Mon, 12 Dec 2005 [EMAIL PROTECTED] wrote: > I'd need to perform simple pattern matching within a string using a list > of possible patterns. For example, I want to know if the substring > starting at position n matches any of the string I have a list, as > below: > >

Re: Pattern matching with string and list

2005-12-12 Thread Michael Spencer
[EMAIL PROTECTED] wrote: > Hi, > > I'd need to perform simple pattern matching within a string using a > list of possible patterns. For example, I want to know if the substring > starting at position n matches any of the string I have a list, as > below: > >

Pattern matching with string and list

2005-12-12 Thread olaufr
Hi, I'd need to perform simple pattern matching within a string using a list of possible patterns. For example, I want to know if the substring starting at position n matches any of the string I have a list, as below: sentence = "the color is $red" patterns = ["blue&

Re: Sequence and/or pattern matching

2005-10-20 Thread Séb
Sorry for the confusion, I think my example was unclear. Thank you Mike for this piece of code who solves a part of my problem. In fact, the sequences are unknown at the beginning, so the first part of the code has to find possible sequences and if those sequences are repeated, counts how many time

Re: Sequence and/or pattern matching

2005-10-20 Thread Mike Meyer
"Séb" <[EMAIL PROTECTED]> writes: > Hi everybody, > > Thanks for the time taken to answer my question. Unfortunatly, it seems > that there's a little confusion about what I want to do. > > In fact, I don't want to search for a particular path between > computers. What I really want is to detect se

Re: Sequence and/or pattern matching

2005-10-20 Thread Séb
Hi everybody, Thanks for the time taken to answer my question. Unfortunatly, it seems that there's a little confusion about what I want to do. In fact, I don't want to search for a particular path between computers. What I really want is to detect sequences of connection that are repeated along t

Re: Sequence and/or pattern matching

2005-10-19 Thread Mike Meyer
"Séb" <[EMAIL PROTECTED]> writes: >> Essentially, if I understand correctly, you want to detect LOOPS given a >> sequence of directed connections A->B. "loop detection" and "graph" >> would then be the keywords to search for, in this case. > > Exactly, but the sequence has to be discovered by the

Re: Sequence and/or pattern matching

2005-10-19 Thread Ben Sizer
Séb wrote: > 1) I have a list of connexion between some computers. This list has > this format : It looks like you want graph theory. > Ip A Date Ip B > ...... ... > 192.168.0.119.10.2005 192.168.0.2 > 192.168.0.319.10.2

Re: Sequence and/or pattern matching

2005-10-19 Thread Séb
> Essentially, if I understand correctly, you want to detect LOOPS given a > sequence of directed connections A->B. "loop detection" and "graph" > would then be the keywords to search for, in this case. Exactly, but the sequence has to be discovered by the piece of code ! > Does this "then" imp

Re: Sequence and/or pattern matching

2005-10-19 Thread Alex Martelli
Séb <[EMAIL PROTECTED]> wrote: > Hi everyone, > > I'm relatively new to python and I want to write a piece of code who do > the following work for data mining purpose : Essentially, if I understand correctly, you want to detect LOOPS given a sequence of directed connections A->B. "loop detectio

Sequence and/or pattern matching

2005-10-19 Thread Séb
Hi everyone, I'm relatively new to python and I want to write a piece of code who do the following work for data mining purpose : 1) I have a list of connexion between some computers. This list has this format : Ip A Date Ip B ...... ... 192

Re: Pattern Matching Given # of Characters and no String Input; use RegularExpressions?

2005-04-22 Thread Synonymous
Hello! I was trying to create a program to search for the largest common subsetstring among filenames in a directory, them move the filenames to the substring's name. I have succeeded, with help, in doing so and here is the code. Thanks for your help! --- Code --- #This program was created wit

Re: Pattern Matching Given # of Characters and no String Input; use RegularExpressions?

2005-04-20 Thread Synonymous
tiissa <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > Synonymous wrote: > > tiissa <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > > > >>tiissa wrote: > >> > >>>If you know the number of characters to match can't you just compare > >>>slices? > >> > >>If you

Re: Pattern Matching Given # of Characters and no String Input; use RegularExpressions?

2005-04-20 Thread Synonymous
John Machin <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > On 17 Apr 2005 18:12:19 -0700, [EMAIL PROTECTED] (Synonymous) > wrote: > > > > >I will look for a Left$(str) function that looks at the first X > >characters for python :)). > > > > Wild goose chase alert! AFAIK there

Re: Pattern Matching Given # of Characters and no String Input; use RegularExpressions?

2005-04-18 Thread tiissa
Synonymous wrote: tiissa <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... tiissa wrote: If you know the number of characters to match can't you just compare slices? If you don't, you can still do it by hand: In [7]: def cmp(s1,s2): : diff_map=[chr(s1[i]!=s2[i]) for i in r

Re: Pattern Matching Given # of Characters and no String Input; use RegularExpressions?

2005-04-17 Thread John Machin
On 17 Apr 2005 18:12:19 -0700, [EMAIL PROTECTED] (Synonymous) wrote: > >I will look for a Left$(str) function that looks at the first X >characters for python :)). > Wild goose chase alert! AFAIK there isn't one. Python uses slice notation instead of left/mid/right/substr/whatever functions. I do

Re: Pattern Matching Given # of Characters and no String Input; use RegularExpressions?

2005-04-17 Thread Synonymous
tiissa <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > tiissa wrote: > > If you know the number of characters to match can't you just compare > > slices? > If you don't, you can still do it by hand: > > In [7]: def cmp(s1,s2): >: diff_map=[chr(s1[i]!=s2[i]) for i in

Re: Pattern Matching Given # of Characters and no String Input; useRegularExpressions?

2005-04-17 Thread Kent Johnson
tiissa wrote: Synonymous wrote: Can regular expressions compare file names to one another. It seems RE can only compare with input i give it, while I want it to compare amongst itself and give me matches if the first x characters are similiar. Do you have to use regular expressions? If you know the

Re: Pattern Matching Given # of Characters and no String Input; use RegularExpressions?

2005-04-17 Thread tiissa
tiissa wrote: If you know the number of characters to match can't you just compare slices? If you don't, you can still do it by hand: In [7]: def cmp(s1,s2): : diff_map=[chr(s1[i]!=s2[i]) for i in range(min(len(s1), len(s2)))] : diff_index=''.join(diff_map).find(chr(True)) .

Re: Pattern Matching Given # of Characters and no String Input; use RegularExpressions?

2005-04-17 Thread tiissa
Synonymous wrote: Can regular expressions compare file names to one another. It seems RE can only compare with input i give it, while I want it to compare amongst itself and give me matches if the first x characters are similiar. Do you have to use regular expressions? If you know the number of cha

Pattern Matching Given # of Characters and no String Input; use RegularExpressions?

2005-04-17 Thread Synonymous
Hello, Can regular expressions compare file names to one another. It seems RE can only compare with input i give it, while I want it to compare amongst itself and give me matches if the first x characters are similiar. For example: cccat cccap cccan dddfa dddfg dddfz Would result in the 'ddd' a

Re: Pattern matching from a text document

2005-03-24 Thread F. Petitjean
Le 24 Mar 2005 06:16:12 -0800, Ben a écrit : > > Below is a few sample lines. There is the name followed by the class > (not important) followed by 5 digits each of which can range 1-9 and > each detail a different ability, such as fitness, attacking ability > etc. Finally the preferred foot is st

Re: Pattern matching from a text document

2005-03-24 Thread Ben
George Sakkis wrote: > B > "Ben" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > I'm currently trying to develop a demonstrator in python for an > > ontology of a football team. At present all the fit players are > > exported to a text document. > > > > The program reads the docu

Re: Pattern matching from a text document

2005-03-24 Thread Larry Bates
Ben, Others have answered your specific questions, but I thought I'd use this opportunity to make a general statement. Unlike other programming languages, Python doesn't make its built-in functions keywords. You should never, ever, ever name a variable 'list' (the same is true of dict, tuple, st

Re: Pattern matching from a text document

2005-03-23 Thread infidel
First, if you're going to loop over each line, do it like this: for line in file('playerlist.txt'): #do stuff here Second, this statement is referencing the *second* item in the list, not the first: match = ph.match(list[1]) Third, a simple splitting of the lines by some delimiter character

  1   2   >