[Tutor] Printing two elements in a list

kumar s ps_python at yahoo.com
Tue Dec 7 16:22:29 CET 2004


Dear group, 
 I have two lists names x and seq. 

I am trying to find element of x in element of seq. I
find them. However, I want to print element in seq
that contains element of x and also the next element
in seq. 


So I tried this piece of code and get and error that
str and int cannot be concatenated
>>> for ele1 in x:
	for ele2 in seq:
		if ele1 in ele2:
			print (seq[ele1+1])

			

Traceback (most recent call last):
  File "<pyshell#173>", line 4, in -toplevel-
    print (seq[ele1+1])
TypeError: cannot concatenate 'str' and 'int' objects


2. TRIAL TWO:

>>> for ele1 in x:
	for ele2 in seq:
		if ele2 in range(len(seq)):
			if ele1 in ele2:
				print seq[ele2+1]


This is taking forever and I am not getting an answer.


3. TRIAL 3:
I just asked to print the element in seq that matched
element 1 in X.  It prints only that element, however
I want to print the next element too and I cannot get
it. 
>>> for ele1 in x:
	for ele2 in seq:
		if ele1 in ele2:
			print ele2

			
>probe:HG-U95Av2:31358_at:454:493;
Interrogation_Position=132; Antisense;
>probe:HG-U95Av2:31358_at:319:607;
Interrogation_Position=144; Antisense;




>>> len(x)
4504
>>> x[1:10]
['454:494', '319:607', '319:608', '322:289',
'322:290', '183:330', '183:329', '364:95', '364:96']
>>> len(seq)
398169
>>> seq[0:4]
['>probe:HG-U95Av2:1000_at:399:559;
Interrogation_Position=1367; Antisense;',
'TCTCCTTTGCTGAGGCCTCCAGCTT',
'>probe:HG-U95Av2:1000_at:544:185;
Interrogation_Position=1379; Antisense;',
'AGGCCTCCAGCTTCAGGCAGGCCAA']


>>> for ele1 in x:
	for ele2 in seq:
		if ele1 in ele2:
			print ele2

			
>probe:HG-U95Av2:31358_at:454:493;
Interrogation_Position=132; Antisense;
>probe:HG-U95Av2:31358_at:319:607;
Interrogation_Position=144; Antisense;






How Do I WANT:

I want to print get an output like this:


>probe:HG-U95Av2:1000_at:399:559;
Interrogation_Position=1367; Antisense;'
TCTCCTTTGCTGAGGCCTCCAGCTT

>probe:HG-U95Av2:1000_at:544:185;
Interrogation_Position=1379; Antisense;
AGGCCTCCAGCTTCAGGCAGGCCAA


can any one please suggest what is going wrong in my
statements and how can I get it. 

Thank you.
Kumar


		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - 250MB free storage. Do more. Manage less. 
http://info.mail.yahoo.com/mail_250


More information about the Tutor mailing list