Skip to content

Commit 47d73e0

Browse files
committed
Improve clone detection examples
1 parent 636d0f5 commit 47d73e0

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

clones/fib2.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
n = 5
2-
a, b = 0, 1
3-
for _ in range(n):
4-
a, b = b, a + b
5-
print(a)
1+
def fib(n):
2+
a, b = 0, 1
3+
for _ in range(n):
4+
a, b = b, a + b
5+
return a

clones/single_file.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# Here's the first example of duplication
2-
with open("file1.py") as f:
3-
for line in f:
4-
print(line)
5-
print()
2+
def remove_duplicates(items):
3+
result = []
4+
for item in items:
5+
if item not in result:
6+
result.append(item)
7+
return result
68

79

810
# Here's the second example of duplication
9-
with open("file1.py") as f:
10-
for line in f:
11-
print(line)
12-
print()
11+
def remove_duplicates1(items):
12+
result = []
13+
for item in items:
14+
if item not in result:
15+
result.append(item)
16+
return result

0 commit comments

Comments
 (0)