I am trying to parse some data contained within a file:
>in:12 out:8 John
>in:20 out:12 Fred
>in:8 out:2 Danny
I would like to find the maximum in value, and find who has the maximum in (Fred does in my example).
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s a non-standard data format you’ve got there. Hence, you’ve to write a non-standard parser (a better idea would be to use a standard exchange format like JSON and use a parser from the standard library). I’d
Personclass with, say, aninandoutattributePersonPersons from your input file calledpersons.in:persons_sorted = sorted(persons, key=lambda p: p.in)max_in_person = persons_sorted[-1]