184k 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. 2. A list named parking_tickets has been defined to be the number of parking tickets given out by the city police each day since the beginning of the current year. (Thus, the first element of the list contains the number of tickets given on January 1; the last element contains the number of tickets given today.) Write some code that associates most_tickets with the largest value found in parking_tickets. You may, if you wish, use one additional variable, k. Please use Python lists and write in simplest form. This is using codelab so may variables are already set up.

User Sakabako
by
5.8k points

1 Answer

5 votes

Answer:

Question 1

#Definition

zipcode_list = [12562, 45236, 125896, 125624, 23564]

# set(zipcode_list) gives us the list that contains

# Unique values only from zipcode_list

if len(zipcode_list) != len(set(zipcode_list)):

duplicates = True

else:

duplicates = False

print(duplicates)

Question 2

# Initialization

parking_tickets = [77, 83, 12, 210, 54]

# Use max() function to find largest value

most_tickets = max(parking_tickets)

# print the most_tickets

print(most_tickets)

User TheGrandWazoo
by
5.3k points