10.7k views
3 votes
You are given a variable named zipcode_list that has been defined and refers to a list of postal codes. Write some code that assigns True to duplicates if any two elements in the list have the same value, but that otherwise assigns False to duplicates. You may, if you wish, use two other variables, j and k. Use only j, k, zipcode_list, and duplicates.

User Jbchichoko
by
6.1k points

1 Answer

3 votes

Answer:

Since I'm using the other two variables, the coding will be as follows;

duplicates = False

j = 0

while j < len(zipcode_list)-1 and not duplicates:

k = j + 1

while k < len(zipcode_list) and not duplicates:

if zipcode_list[k] == zipcode_list[j]:

duplicates = True

k += 1

j += 1

User Gang Liang
by
5.6k points