How to get the first value in a python dictionary

前端 未结 6 877
遇见更好的自我
遇见更好的自我 2020-12-11 01:02

I have a dictionary like this:

myDict = {  
    \'BigMeadow2_U4\': (1609.32, 22076.38, 3.98),  
    \'MooseRun\': (57813.48, 750187.72, 231.25),  
    \'Hw         


        
6条回答
  •  悲哀的现实
    2020-12-11 01:51

    Try this.Type the dictionary and the position you want to print in the function

    d = {'Apple': 1, 'Banana': 9, 'Carrot': 6, 'Baboon': 3, 'Duck': 8, 'Baby': 2}
    print(d)
    def getDictKeyandValue(dict,n): 
        c=0
        mylist=[]
        for i,j in d.items():
            c+=1
            if c==n:
    
                mylist=[i,j]
                break
        return mylist   
    
    print(getDictKeyandValue(d,2))
    

提交回复
热议问题