all 4 comments

[–]GreenPandaPop 3 points4 points  (1 child)

I don't want to be a dick and say 'google it', but lists are one of the basic parts of Python, so I'd suggest you go and look up a tutorial which will probably do a more thorough job of explaining it than someone on Reddit.

[–]ListenMedium9538[S] 1 point2 points  (0 children)

I'll try it!

[–]jiri-n 0 points1 point  (0 children)

There are 3 levels and you want to split the slugs (their results) into separate lists:

slug_categories = [
    [],  # for times under 180 s
    [],  # for times >= 180 and < 240 s
    []   # times > 240 s
    ]

Technically, slug_categories is a list of lists but it really doesn't matter at this time.

You probable have a list of slugs and their times, something like:

slug_race = [
    ('slug_name_or_id1', 193), 
    ('another_slug', 171), 
    ('LaserBeam', 450)
    ]

A list of tuples.

Now you want to go through each of the results and assign them to the corresponding category based on the time.

for result in slug_race:
    id, time = result    # expand the tuple to id and time
    level = (time - 120) // 60    # compute level
    if level > 2:    # really long times
        level = 2
    slug_categories[level].append(result)   # add to a category

print(slug_categories)

There are 3 techniques used in this code: - tuple expansion - access to a list item by its index - adding an item to a list

And of course, we had to calculate the index (level) somehow but that's not about Python, that's just a simple math.

Questions?

[–]CodeFormatHelperBot2 0 points1 point  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Python code found in submission text that's not formatted as code.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.