PYTHON   37
keysWithValue
Guest on 26th August 2023 12:35:31 AM


  1. #d = {1:1, 2:2, 3:3, 4:3, 5:3}
  2. def keysWithValue(aDict, target):
  3.     '''
  4.    aDict: a dictionary
  5.    target: an integer
  6.    '''
  7.     # Your code here
  8.     ans = []
  9.     for k, v in aDict.items():
  10.         if v == target:
  11.             ans.append(k)
  12.     return sorted(ans)
  13.    
  14.  
  15.    
  16. #print(keysWithValue(d, 3))

Raw Paste

Login or Register to edit or fork this paste. It's free.