searching structures

Lane LiaBraaten lliabraa at isrparc.org
Tue Oct 21 11:19:59 EDT 2003


On Tuesday 21 October 2003 09:54 am, Alberto Vera wrote:
> Hello:
>
> I have next structures:
>
> A[1,2,3]
> AB[4,5,6]
> ABC[7,8,9]
> ABCD[1,2,3]
> ABCDE[4,5,6]
> ABCDEF[7,8,9]
>

You could use a dictionary:
#-----------------------------
Arrays={
		A:[1,2,3],
		AB:[4,5,6],
		ABC:[7,8,9],
		# etc., etc.
}
#-----------------------------

> I'd like to know how many 'arrays' start with ABCD like ABCD*
> (ABCD,ABCDE,ABCDEF)
>

Then import the re module to search Arrays.keys() for regular expressions:

#------------------------
import re

pattern=re.compile('ABCD*')

for key in Arrays.keys():
	if pattern.search(key)!=None:
		# Then you found an arrray that starts with ABCD
#-------------------------

Note: The re module is dprecated (or obsolecent or whatever ;-) but I haven't 
used the suggected regex module.

LGL





More information about the Python-list mailing list