Last active
November 10, 2019 15:44
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
and thats the same without the with statment:
function GetLocalIpList: TStringList;
var
TcpBlockSocket : TTcpBlockSocket;
begin
Result:= TStringList.Create;
TcpBlockSocket := TTcpblockSocket.Create;
TcpBlockSocket.ResolveNameToIP(TcpBlockSocket.LocalName,Result);
TcpBlockSocket.Free; //Destroy;
end;
two ways to go:
>>> mylist
['abc', '123', '758', 'cde', '123', '123']
>>> re.sub("[\D]", "", str(mylist))
'123758123123'
>>> ''.join(n for n in mylist if n.isdigit())
'123758123123'
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
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
so we have to test the memory destructor of: