-
Notifications
You must be signed in to change notification settings - Fork 4
/
es3-equals.py
51 lines (40 loc) · 1.32 KB
/
es3-equals.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
##
# Determine if 2 lists are equal.
#
# Define constants.
LIST_1 = [1, 2, 3]
LIST_2 = [1, 2, 3]
def main():
print("List 1 is", LIST_1)
print("List 2 is", LIST_2)
print("List 1 and List 2 are equal: ", equalsOneByOne(LIST_1, LIST_2))
# Determine if two lists have the same elements in the same order.
# @param l1 the first list to consider
# @param l2 the second list to consider
# @return True if the lists are the same, otherwise False
#
def equalsOneByOne(l1, l2):
equal = True
if len(l1) == len(l2):
i = 0
while i < len(l1) and equal:
# If an element at the i position in the first list is different
# from the element in such position in the second list, the iteration
# is stopped by setting 'equal' to false.
if l1[i] != l2[i]:
equal = False
i = i + 1
else:
equal = False
return equal
# Shortcut: in Python the '==' comparison operator already checks whether the two lists
# contain the same elements in the same order
# Determine if two lists have the same elements in the same order.
# @param l1 the first list to consider
# @param l2 the second list to consider
# @return True if the lists are the same, otherwise False
#
def equals(l1, l2):
return l1 == l2
# Call the main function.
main()