28 lines
731 B
Python
28 lines
731 B
Python
"""Demo script for users: contains several detectable anti-patterns.
|
|
|
|
- membership test against a list inside a loop -> membership_in_list
|
|
- nested loops -> nested_loops
|
|
- string concatenation with += inside a loop -> str_concat_loop
|
|
"""
|
|
|
|
|
|
def build_report(rows, allow):
|
|
out = ""
|
|
for r in rows:
|
|
if r in allow: # O(n) membership test on a list
|
|
out += str(r) + "," # string += accumulation
|
|
for other in rows: # nested loop -> O(n^2)
|
|
if r == other:
|
|
pass
|
|
return out
|
|
|
|
|
|
def main():
|
|
rows = list(range(400))
|
|
allow = list(range(0, 400, 2))
|
|
for _ in range(30):
|
|
build_report(rows, allow)
|
|
|
|
|
|
main()
|