Unable to load image

r/drama Advent of Code S02E01 - Official DISCUSSION Thread

Ok you Python-using heathens. What did you think for difficulty this time around?

Post your coding atrocities below.

For those of you who missed the early signups. Feel free to join the leaderboard late (though rankings are based on time).

42
Jump in the discussion.

No email address required.

I got both puzzles but don't laugh at my solution for the 2nd one :marseysad:

I've been very, very slowly teaching myself Python after learning Matlab at college

https://i.rdrama.net/images/17014130661729786.webp https://i.rdrama.net/images/17014130662879624.webp

Jump in the discussion.

No email address required.

:#capyhackerlove::#capyhackerlove::#capyhackerlove:

Proud of you, little buddy.

Jump in the discussion.

No email address required.

Everywhere that you think you need a tree of if/elif/else based on the same value you can use a dict:

val_map = {
 'one': 1,
 'two': 2,
 # ...
}

Then you get the value using val1 = val_map[val1] or if you need a default, your else here, use .get(key, default):

val1 = val_map.get(val1, int(val1))
Jump in the discussion.

No email address required.

zoz

Jump in the discussion.

No email address required.

zle

Jump in the discussion.

No email address required.

zozzle

Jump in the discussion.

No email address required.

:marseynotes:

That's a better example of the use of a dictionary than anything those coding bootcamps told me

Jump in the discussion.

No email address required.

Never be ashamed of your solution if it gets the work done.

Especially since your solution is clean and understandable by everyone. Sure it's a bit convoluted, but who cares ;)

Jump in the discussion.

No email address required.

Part 2 solution is keyed, ignore the haters

Jump in the discussion.

No email address required.

I think your solution for the second one is really cute. In the future you can just use rfind though.

I love the little word games some people play with it to get it to work

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.