[Tutor] Selecting text

Ewald Ertl ewald.ertl at hartter.com
Wed Jan 19 09:29:26 CET 2005


Hi kumar

If I unterstood your question correctly, you have to iterate over the refseq until 
you get the next entry, which starts with a '>'

on Tue, 18 Jan 2005 20:12:32 -0800 (PST)  kumar s <ps_python at yahoo.com> wrote :
---------------------------------------------------------------------------------------------


kumar s > I could not think of any smart way to do this,
kumar s > although I have tried like this:
kumar s > 
kumar s > >>> for ele1 in Lseq:
kumar s > 	for ele2 in refseq:
kumar s > 		if ele1 in ele2:
kumar s > 			k = ele2
kumar s > 			s = refseq[ele2].startswith('>')

Here you index the list with an element, but the index must be an integer

kumar s > 			print k,s
kumar s > 
kumar s > 			
kumar s > 
kumar s > Traceback (most recent call last):
kumar s >   File "<pyshell#261>", line 5, in -toplevel-
kumar s >     s = refseq[ele2].startswith('>')
kumar s > TypeError: list indices must be integers
kumar s > 
kumar s > 
kumar s > I do not know how to dictate to python to select lines
kumar s > between two > symbols. 
kumar s > 


------------------- end ----------------------
Perhaps this is a possible solution: 

Iteration of Lseq an then looping over all elements in refseq. 
if an element of refseq contains the ele1 the list-entry is printed. 
The nested while-loop print's the refseq -elements as long as the element
does not start with a '>'

for ele1 in Lseq:
	i=0
	while i < len(refseq):
 		if ele1 in refseq[i]:
			print refseq[i]
			i +=1
			while not refseq[i].startswith('>'):
				print refseq[i]
				i+=1 # increment until the next entry starting with '>' is found
		i +=1 # if search should continue if another element is present

HTH Ewald



-- 
Ing. Ewald Ertl         HartterGruppe                   Phone : +43-3352-33085-558
trinomic Projektmanagement & Informationstechnik GmbH   Fax   : +43-3352-33085-600
Wiener Straße 41                                        mailto:ewald.ertl at trinomic.com
A-7400 Oberwart         http://www.trinomic.com         mailto:ewald.ertl at hartter.com



More information about the Tutor mailing list