Skip to content

Instantly share code, notes, and snippets.

@maxkleiner
Last active November 10, 2019 15:44
Show Gist options
  • Save maxkleiner/2c1cad2aa531870eff083f99ddfce225 to your computer and use it in GitHub Desktop.
Save maxkleiner/2c1cad2aa531870eff083f99ddfce225 to your computer and use it in GitHub Desktop.
DefaultDict is a dictionary that is initialized with a default value when each key is encountered for the first time.
#my_default_dict = {}
from collections import defaultdict
# to prevent key error - KeyError: 't'
my_default_dict = defaultdict(int)
for letter in 'the red maXbox fox ran as fast as it could':
my_default_dict[letter] += 1
print(my_default_dict)
@maxkleiner
Copy link
Author

{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure OutputDebugStr(const AMsg: String); {$IFDEF USE_INLINE} inline; {$ENDIF}
begin
  {$IFDEF POSIX}
    System.WriteLn(AMsg);
  {$ENDIF}
  {$IFDEF MSWINDOWS}
    {$IFDEF RTL_NAMESPACES}Winapi.{$ENDIF}Windows.OutputDebugString(PChar(AMsg));
  {$ENDIF}
end;

https://drive.google.com/open?id=1MFIhQvmEQFtEWWTNiIWrthSAwAnufGKG

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment