MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / normalize_defensive

Function normalize_defensive

example_code/item_021.py:145–153  ·  view source on GitHub ↗
(numbers)

Source from the content-addressed store, hash-verified

143
144print("Example 12")
145def normalize_defensive(numbers):
146 if iter(numbers) is numbers: # An iterator -- bad!
147 raise TypeError("Must supply a container")
148 total = sum(numbers)
149 result = []
150 for value in numbers:
151 percent = 100 * value / total
152 result.append(percent)
153 return result
154
155
156visits = [15, 35, 80]

Callers 1

item_021.pyFile · 0.85

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected