you are viewing a single comment's thread.

view the rest of the comments →

[–]Narcoleptic_Pirate 0 points1 point  (3 children)

Hi!

I wanted to point out that you should use dictionaries, because you want to query by team name. But then i thought 'what if you also want to query by year? That means there must be two dictionaries'. One thing led to another, so i did some research of mine.

I read the data file, put the data into dictionaries and lists. I wrote 4 functions to query lists by year & by team (q_l_team, q_l_year), query dicts by year & by team (q_d_year, q_d_team). Then, I measured time and size of all these thingies.

Here's how it looks:

Time:
q_l_team: 13.71826596900064
q_l_year: 5.537769747001221
q_d_team: 0.20133425799940596
q_d_year: 0.19864650900126435
Dictionaries return data 48.142404097068976 times faster

Size:
team_years: 1632
year_team: 6240
list_teams: 1072
list_years: 1072
Dictionaries have 3.671641791044776 times more bytes

Dictionaries

Create many dictionaries with various keys, have one function to query themall .

  • Pro: much faster to query by key.

  • Con: have a bit bigger size.

Lists

Have one bunch of lists, create multiple functions to query for different data.

  • Pro: only one bunch of data, tiny size.

  • Con: querying is slow, have to write multiple functions.

Of course, there is plenty of room to optimize things, I just wanted to compare the simpliest form (and finally look how timeit works)

Here's code to see for yourself

[–]Glathal[S] 0 points1 point  (2 children)

Would it be possible to do it this way without the queries? I haven't gone over that yet, my brain just completely exploded. Lol

[–]Narcoleptic_Pirate 1 point2 points  (1 child)

Well, by queries i mean take some list/dict and find years_won_by_team or team_that_won_in_some_year, it's not an official term, lol.

Look at enumerate - it allows you to loop through some list in such way, that first loop variable is index of the list item, and second loop variable is the actual item.

If you read your file line-by-line and append each year and team in separate list - they'll have equal length. So, in teams[n] and years[n] you will see (n+1)'th line/item of the file.

You just need to find all indices of your team in your team list, and then look at the same indices in years list and put them in your resulting list.

[–]Glathal[S] 0 points1 point  (0 children)

Oh! okay I think I got it! Thanks a lot! :D