Created
January 5, 2024 03:50
-
-
Save audiodude/ca43f20ecc0b4709f85bb187da096375 to your computer and use it in GitHub Desktop.
Increment random value from a dictionary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fruits={'apple': 0.49, 'banana': 0.69, 'peach': 1.29, 'pear': 1.49, 'watermelon': 2.99} | |
Incrementing banana by 1 | |
fruits={'apple': 0.49, 'banana': 1.69, 'peach': 1.29, 'pear': 1.49, 'watermelon': 2.99} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
fruits = { | |
'apple': 0.49, | |
'banana': 0.69, | |
'peach': 1.29, | |
'pear': 1.49, | |
'watermelon': 2.99, | |
} | |
print(f'{fruits=}') | |
key = random.choice(list(fruits.keys())) | |
print(f'Incrementing {key} by 1') | |
fruits[key] += 1 | |
print(f'{fruits=}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment