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

so we have to test the memory destructor of:

function GetLocalIpList2(localname: string): TStringList;
begin
  with TTCPblockSocket.Create do 
  try 
    Result:= TStringList.Create;
    ResolveNameToIP(localname,Result);
  finally  
    Free; //Destroy;
  end;  
end;

@maxkleiner
Copy link
Author

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;

@maxkleiner
Copy link
Author

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'

@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