Skip to content
Advertisement

Python create lists conditionally from txt file

I have a txt file with this structure of data:

3
100 name1
200 name2
50 name3
2
1000 name1
2000 name2
0

The input contains several sets. Each set starts with a row containing one natural number N, the number of bids, 1 ≤ N ≤ 100. Next, there are N rows containing the player’s price and his name separated by a space. The player’s prize is an integer and ranges from 1 to 2*109.

Expected out is:
Name2
Name2

How can I find the highest price and name for each set of data?

I had to try this:(find the highest price)

JavaScript

This creates a list of all sets but not one by one. Thank you for your advice.

Advertisement

Answer

You’ll want to manually loop over each set using the numbers, rather than a for loop over the whole file

For example

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement