searching structures

Gerrit Holl gerrit at nl.linux.org
Tue Oct 21 11:12:02 EDT 2003


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]
> 
> I'd like to know how many 'arrays' start with ABCD like ABCD*
> (ABCD,ABCDE,ABCDEF)
> 
> Is it possible to do it using Python?

Do you mean that you have a file containing this lines?
If so, you may want to do something like:

counter = 0
for line in file(f):
    if line.startswith("ABCD"):
        counter += 1

Or, shorter:

count = len([l for l in file(f) if l.startswith("ABCD")])

Or do you mean something else?

yours,
Gerrit.
-- 
222. If he were a freed man he shall pay three shekels.
          -- 1780 BC, Hammurabi, Code of Law
-- 
Asperger Syndroom - een persoonlijke benadering:
	http://people.nl.linux.org/~gerrit/
Kom in verzet tegen dit kabinet:
	http://www.sp.nl/





More information about the Python-list mailing list