Skip to content
  • Tutorials
    • c programming
      • libraries
    • c++
    • Linux
    • Python
    • batch programming
    • Technology
  • IDE
  • Tools
append to list in dictionary python if exists 1

append to list in dictionary python if exists

May 14, 2022 by Anurag batra
dic.setdefault(key,[]).append(value)

Here is what the above code is Doing:
1. It’s creating a dictionary called dic.
2. It’s setting the default value of dic[key] to an empty list.
3. It’s appending value to the list.

Categories Python Examples
Post navigation
discord.py make command admin only
difference between set and list in python
© MyEduKit - 2022 . All Rights Reserved.