Question on Joining of list

Peter Otten __peter__ at web.de
Fri Jul 18 05:57:11 EDT 2008


SUBHABRATA wrote:

> I am trying the following code line:

def try2(n):
    user_line = raw_input("PRINT A STRING:")
    user_words = user_line.split()
    my_line = "God Godess Heaven Sky"
    for word in user_words:
        pos = my_line.find(word)
        if pos >- 1:
            first_char = my_line[pos]
            print first_char
        elif pos < 0:
            missing_word = word
            print "It is not found"
            print missing_word
        else:
            print "Error"
    s = first_char + " " + missing_word
    print s

try2(1)

Do you recognise your code? With that jumpstart you should find the error in
no time ;)

> Here, if I put a string like:
> Petrol Helium Heaven Sky
> In s it is giving me S Helium
> But I am looking for an output of  a5 and a6 concatenating all its
> values not the last ones. Can you suggest me any help? Am I missing
> any minor point?

Yes, use meaningful variables. They won't make your code magically correct
but will make it a lot easier to pinpoint mistakes and false assumptions --
for you and others.

Peter



More information about the Python-list mailing list