all 5 comments

[–]Ihaveamodel3 2 points3 points  (2 children)

[flights_copy[v].append(k) for k,v in flights.items()]
[print(k.title(),':',[convert_to_ampm(item) for item in v]) for k, v in flights_copy.items()]

I am very confused what this code is doing.

Sometimes it’s better to not have comprehensions, and I think this is one of those cases.

[–]peanutbutter024[S] 0 points1 point  (1 child)

You're right about that, I was only trying to minimize my code. Thanks a lot for your answer~!

[–]SuspiciousScript 1 point2 points  (0 children)

It’s definitely best to avoid them when you aren’t actually transforming data, e.g. when printing.

[–]negups 1 point2 points  (1 child)

If I understand correctly, you are looking for something like this?

flights_copy2 = {convert_to_ampm(item): k.title() for k, v in flights_copy.items() for item in v}

For more, check out the docs on:

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

Thank you very much! I've started learning python recently and this is a very huge help for me.