MCPcopy
hub / github.com/nsonaniya2010/SubDomainizer / entropy

Function entropy

SubDomainizer.py:321–337  ·  view source on GitHub ↗

This function find the entropy given the string given by the formula: https://www.reddit.com/r/dailyprogrammer/comments/4fc896/20160418_challenge_263_easy_calculating_shannon/ Parameters ------- s: str String of which we have to find shannon entropy Returns --

(s)

Source from the content-addressed store, hash-verified

319
320
321def entropy(s):
322 """
323
324 This function find the entropy given the string given by the formula:
325 https://www.reddit.com/r/dailyprogrammer/comments/4fc896/20160418_challenge_263_easy_calculating_shannon/
326
327 Parameters
328 -------
329 s: str
330 String of which we have to find shannon entropy
331
332 Returns
333 --------
334 int
335 integer which will represent the randomness of the string, higher value will be high randomness.
336 """
337 return -sum(i / len(s) * log2(i / len(s)) for i in Counter(s).values())
338
339
340def getDomain(url):

Callers 2

getInfoFromDataFunction · 0.85
SubDomainizer.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected