Can someone come up with a kivy python code where we define keys and values

38 Views Asked by At

If we give any key as the input we should get the corresponding values as the output and if we give any one element from a list as input, we should get the corresponding key as the output.Please ignore enter code here in the middle

Following is keys and their values

"RCB" : ["Virat", "Abd", "Maxwell","Chahal"], "CSK": ["Dhoni", "Raina", "Jadeja", "Faf"], "KKR": ["Morgan", "Russell", "Karthik", "Naenter code hereine"], "PBKS" : ["Rahul", "Mayank", "Shami", "Gayle"]

1

There are 1 best solutions below

2
Weebify On

I believe this is what you wanted:

dict = {
    "RCB" : ["Virat", "Abd", "Maxwell","Chahal"], 
    "CSK": ["Dhoni", "Raina", "Jadeja", "Faf"],
    "KKR": ["Morgan", "Russell", "Karthik", "Naenter code hereine"],
    "PBKS" : ["Rahul", "Mayank", "Shami", "Gayle"]
}

def getOutput(dict, value):
    try:
        output = dict[value]
        return output
    except KeyError:
        for key in dict:
            if value in dict[key]:
                output = key
                return output
    return None

print(getOutput(dict, "RCB")) 
#["Virat", "Abd", "Maxwell","Chahal"]
print(getOutput(dict, "Raina"))
#"CSK"