Skip to content

Instantly share code, notes, and snippets.

@dskecse
Created December 3, 2023 21:19
Show Gist options
  • Save dskecse/f58134c60ae44ba03b5d13f9813728b8 to your computer and use it in GitHub Desktop.
Save dskecse/f58134c60ae44ba03b5d13f9813728b8 to your computer and use it in GitHub Desktop.

Revisions

  1. dskecse created this gist Dec 3, 2023.
    11 changes: 11 additions & 0 deletions default.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    from collections import defaultdict

    dict = defaultdict(lambda : 0)
    dict["a"]
    # => 0
    dict.keys()
    # => dict_keys(['a'])
    print(dict.get("b"))
    # => None
    dict.keys()
    # => dict_keys(['a'])
    3 changes: 3 additions & 0 deletions default.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    hash = Hash.new(0)
    hash[:a]
    # => 0