dictionary removing specific key

Solutions on MaxInterview for dictionary removing specific key by the best coders in the world

showing results for - "dictionary removing specific key"
Ryland
20 Oct 2018
1>>> incomes = {'apple': 5600.00, 'orange': 3500.00, 'banana': 5000.00}
2>>> non_citric = {k: incomes[k] for k in incomes.keys() - {'orange'}}
3>>> non_citric
4{'apple': 5600.0, 'banana': 5000.0}
5
Sara
20 Jun 2020
1>>> # Python 3.6, and beyond
2>>> incomes = {'apple': 5600.00, 'orange': 3500.00, 'banana': 5000.00}
3>>> sorted_income = {k: incomes[k] for k in sorted(incomes)}
4>>> sorted_income
5{'apple': 5600.0, 'banana': 5000.0, 'orange': 3500.0}
6