At 08:22 AM 12/7/2004, kumar s wrote:
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])

The problem here is that ele1 is a string, not an index into the list. There are a couple ways to fix this.


match = False
for ele1 in x:
    for ele2 in seq:
        if match:
            print ele2
            match = False
        if ele1 in ele2:
            print ele2
            match = True
OR

for ele1 in x:
    for index, ele2 in enumerate(seq):
        if ele1 in ele2:
            print ele2, seq[index+1]

[snip]

Bob Gailer
[EMAIL PROTECTED]
303 442 2625 home
720 938 2625 cell


_______________________________________________
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to