dictionaries in dictionary, Python 3

-1

I have a dictionary with lists:

d1 = {
  'Carlos': {
     'manzanas': ['12', 'verdes', '7', 'rojas', '5'],
      'uvas': ['8', 'negras', '5', 'verdes', '3']
   },
   'Juan': {
      'manzanas': ['7', 'verdes', '5', 'rojas', '2'],
      'uvas': ['9', 'negras', '9'], 'pomelo': ['12', 'amarillo', '5', 'rosado', '7'] 
   },
   'Pedro': {
      'manzanas': ['14', 'verdes',' 6', ' rojas', ' 8'], 'pomelo': ['19', 'amarillo', '10', 'rosado', '9'] 
   }
}

I would like to do a function where I enter a fruit and show me ONLY who has more quantity of it (the quantity is the first number of the list of each fruit), also the types of that fruit and their respective quantity.

** Detail: d1 is loaded from a .csv file on my PC. The function should serve me for any other .csv file (of the same format) that opens in Python. The program to open the file and place it on d1 has already been done.

    
asked by Jarni Garay 24.10.2018 в 01:00
source

1 answer

0

I used a bubble but I think this is what you are looking for:

def quien_tien_mas(fruta):
  mayor = 0
  quien = None
  for persona in d1:
    if fruta in d1[persona] and len(d1[persona][fruta]) > 0 and int(d1[persona][fruta][0]) > mayor:
      mayor = int(d1[persona][fruta][0])
      quien = persona
  return quien, mayor
    
answered by 24.10.2018 в 08:06