data.txt
May-2017-120-245.50
Jun-2017-124-21.50
Jun-2017-110-34.00
Jun-2017-120-200.00
Jul-2017-124-546.50
Jul-2017-110-1500.00
Jun-2017-124-245.50
代码:
info = {}
with open('/home/bista/Desktop/data.txt') as input_file:
for line in input_file:
month,year, emp_id, bill_amount = (item.strip() for item in line.split('-', 4))
month = dict(zip(('month','month'),map(str, month.split('/'))))
info[id] = dict(zip(('month','emp_id','bill_amount'),(month,emp_id, bill_amount)))
# print(info)
create_new_dict = {}
for id, record in info.items():
# print(record)
if record['month']['month'] == 'Jun':
new= {record['emp_id']:{'emp_id':record['emp_id'],'bill_amount':record['bill_amount']}}
# print(new)
create_new_dict.update(new)
# print("s",create_new_dict)
max = 0.0
for key,value in create_new_dict.items():
# print(max)
if float(value['bill_amount']) > max:
max =float(value['bill_amount'])
# print("emp_id:",value['emp_id'])
print("emp_id:",value['emp_id'])
问题:
打印结果:
root@bista:/home/bista/Desktop# python3 get.py
emp_id: 124
emp_id: 110
emp_id: 120
emp_id: 124
但结果应为emp_id:124