Ваши данные плохо организованы; zip
может помочь.
Определить предикат помощника:
def is_fit(age, health):
if age > 20 and health == 'Good':
return 'yes'
else:
return 'no'
Реорганизовать данные:
import pprint
a = {'names': 'jason peter mary'.split(),
'ages': [25, 35, 45],
'health': ['Good', 'Good', 'Poor']}
pprint.pprint(list(zip(a['names'], a['ages'], a['health'])), width=30)
[('jason', 25, 'Good'),
('peter', 35, 'Good'),
('mary', 45, 'Poor')]
Теперь вы можете посещать атрибуты каждого человека вместе:
for name, age, health in zip(a['names'], a['ages'], a['health']):
if is_fit(age, health) == 'yes':
print(name)
a['fit'] = [is_fit(age, health)
for age, health
in zip(a['ages'], a['health'])]