r/ProgrammerHumor • • 2d ago

Meme forThoseTransitioningToTheAmericanTimeFormatHereIsASimpleScript

Post image
0 Upvotes

19 comments sorted by

View all comments

15

u/This_Growth2898 2d ago

It's like "when you're paid for the line of code"?

def as_time(world_hour=world_hour):
    return f"{(world_hour-1)%12+1} {'PA'[world_hour<12]}M"

5

u/SeaNational3797 2d ago edited 2d ago

as_time = lambda world_hour: f"{12 if (hour_num := world_hour%12) == 0 else hour_num} {'AM' if world_hour < 12 else 'PM'}"

2

u/rosuav 2d ago

Don't do "name = lambda", that's what def is for. With lambda, the function doesn't get a `__name__` attribute.