Skip to content

Instantly share code, notes, and snippets.

@stephengruppetta
Created December 7, 2023 09:32
Show Gist options
  • Save stephengruppetta/730b4cab79adab3b160059de134e81fd to your computer and use it in GitHub Desktop.
Save stephengruppetta/730b4cab79adab3b160059de134e81fd to your computer and use it in GitHub Desktop.
import random
import heapq
numbers = [random.randint(1, 50) for _ in range(20)]
print(numbers)
# 'max()' with a different rule.
# Can you figure out the rule?
print(
heapq.nlargest(
3,
numbers,
key=lambda x: sum(int(y) for y in str(x)),
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment