[Tutor] Search function in a list-tuples

Christopher Brookes chris.klaitos at gmail.com
Fri Feb 25 15:11:01 CET 2011


Hi, is there a better way to do this ? (*heros are Character*)

herosAll = [
Character(0,"Chris","Soldat fort",type[0],15,5,8,50,1),
Character(1,"Antaa","Soldat moins fort",type[0],15,5,8,50,1)]


def HeroExist(HerosName):
        herosId = -1
        for heros in herosAll:
            if HerosName in heros.name:
                herosId = heros.id
        if herosId != -1:
            return herosId
        else:
            return -1

I find this solution myself and I think a better one exist..

    HerosName=input("Enter heros name : ")
            if Character.HeroExist(HerosName) != -1:

herosAll[Character.HeroExist(HerosName)].DisplayCharacterInfos()
            else :
                print ('This heros does\'nt exist')
            Display_menu()

Ty :)
-- 
Brookes Christopher.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110225/29b0b961/attachment.html>


More information about the Tutor mailing list