Answers for "dictionary tricks"

1

dictionary tricks

>>> objects = ['blue', 'apple', 'dog']
>>> categories = ['color', 'fruit', 'pet']
>>> a_dict = {key: value for key, value in zip(categories, objects)}
>>> a_dict
{'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}
Posted by: Guest on January-29-2021
0

dictionary tricks

>>> total_income = sum(value for value in incomes.values())
>>> total_income
14100.0
Posted by: Guest on June-03-2021
0

dictionary tricks

>>> a_dict = {'one': 1, 'two': 2, 'thee': 3, 'four': 4}
>>> new_dict = {k: v for k, v in a_dict.items() if v <= 2}
>>> new_dict
{'one': 1, 'two': 2}
Posted by: Guest on June-03-2021
0

dictionary tricks

>>> incomes = {'apple': 5600.00, 'orange': 3500.00, 'banana': 5000.00}
>>> total_income = sum([value for value in incomes.values()])
>>> total_income
14100.0
Posted by: Guest on June-03-2021
0

dictionary tricks

>>> a_dict = {'one': 1, 'two': 2, 'thee': 3, 'four': 4}
>>> new_dict = {value: key for key, value in a_dict.items()}
>>> new_dict
{1: 'one', 2: 'two', 3: 'thee', 4: 'four'}
Posted by: Guest on June-03-2021

Browse Popular Code Answers by Language