• Sign in
  • Sign up 
  • Welcome
  • FAQ
  • Switch to Night Mode
  • Stolen Accounts Recovery 
  • Change Account Password 
  • Vote for Witnesses 
  • Steem Proposals 
  • Developer Portal 
  • Steem Bluepaper 
  • SMT Whitepaper 
  • Steem Whitepaper 
  • Privacy Policy
  • Terms of Service
Homeby Witness Moecki
LoginSign up

use dict.get() to increase value

timknip (60)in #note-timknip • 5 years ago
a_dict = {"a":1}

a_dict["b"] = a_dict.get("b", 0) + 1

print(a_dict)
> {'a': 1, 'b': 1}

a_dict["a"] = a_dict.get("a", 0) + 1

print(a_dict)
> {'a': 2, 'b': 1}
#dict #python
5 years ago in #note-timknip by timknip (60)
$0.25
  • Past Payouts $0.25
  • - Author $0.13
  • - Curators $0.13
4 votes
  • + steem-agora
  • + roseofmylife
  • + cnbuddy
  • + cnbuddy-reward
Reply 0