Programming exercise - remove duplicates in a list

Assignment Help Python Programming
Reference no: EM133059368

Learning Activity: Programming Exercise - Remove duplicates in a list

NOTE: this learning activity requires Python 3.6 or higher. In Module 1.1, you were asked to install any Python version higher than 3.6. If you use a version lower than Python 3.6, some of the code will not work.

Removing duplicates in a list is commonly used in everyday life. For example, when merging Google contacts with your iCloud contacts, you may find many duplicated contacts that need to be removed. Sometimes, when you combine multiple sources of photos, you may find duplicates. In this learning activity, you are asked to implement an algorithm that removes duplicated elements in a list.

Your program will first start with the following two lines of code:
import random
l = random.choices(range(50), k = 100)

These two lines of code create a list, l, which contains 100 integers randomly samples from range [0, 50). This range includes the left-hand number 0, but does not include the right-hand side number 50. For example, this can be a list generated by these two lines of code:

[42, 43, 3, 28, 44, 32, 33, 8, 20, 2, 16, 23, 17, 9, 46, 26, 21, 14, 14, 40, 36, 36, 13, 2, 41, 41, 12, 18, 1, 28, 29, 16, 7, 16, 6, 25, 29, 6, 38, 21, 3, 33, 10, 6, 0, 14, 37, 8, 8, 42, 27, 34, 32, 44, 46, 33, 4, 19, 10, 4, 30, 21, 47, 31, 12, 46, 22, 47, 45, 33, 6, 45, 32, 21, 16, 32, 46, 36, 16, 43, 46, 8, 6, 23, 9, 33, 1, 11, 37, 39, 24, 9, 36, 20, 8, 17, 36, 40, 17, 21]
You will first print this list generated by the two lines of code above. You will then write an algorithm remove the duplicates from this list (e.g. 44 appears more than once), output only the unique numbers in the list. The purpose of this exercise is to improve your algorithmic design skills and to practice looping techniques, therefore you should not use other language features (e.g. the set data structure) to "bypass" the purpose of this exercise.

Sample output:
>>> [42, 43, 3, 28, 44, 32, 33, 8, 20, 2, 16, 23, 17, 9, 46, 26, 21, 14, 14, 40, 36, 36, 13, 2, 41, 41, 12, 18, 1, 28, 29, 16, 7, 16, 6, 25, 29, 6, 38, 21, 3, 33, 10, 6, 0, 14, 37, 8, 8, 42, 27, 34, 32, 44, 46, 33, 4, 19, 10, 4, 30, 21, 47, 31, 12, 46, 22, 47, 45, 33, 6, 45, 32, 21, 16, 32, 46, 36, 16, 43, 46, 8, 6, 23, 9, 33, 1, 11, 37, 39, 24, 9, 36, 20, 8, 17, 36, 40, 17, 21]
>>> [38, 23, 11, 2, 36, 24, 13, 45, 32, 22, 1, 37, 18, 16, 0, 20, 39, 33, 21, 27, 10, 29, 30, 34, 4, 46, 25, 19, 17, 12, 43, 7, 31, 8, 6, 28, 47, 44, 14, 41, 42, 3, 26, 9, 40]

This learning activity asks you to write a program.


Attachment:- Remove duplicates in a list.rar

Reference no: EM133059368

Questions Cloud

What amount of insurance will expire each month : Atlas Inc. paid premium of $3,600 for a three-year general business insurance policy that covers risks from fire and theft. What amount of insurance will expire
Prepare general journal entries for the transactions : Assume that depreciation of 12% per year is charged on all machinery and 5% per year on buildings, Prepare general journal entries for the transactions
Prepare a journal entry to record the sale : Prepare a journal entry to record the sale of one Model 217A forklift truck plus service contract for $164,600 assuming
Calculate and provide a brief cost-benefit analysis : While Financial Services industry is not much impacted from the Carbon Tax compared to other industries, Calculate and provide a brief cost-benefit analysis
Programming exercise - remove duplicates in a list : Programming Exercise - Remove duplicates in a list - Implement an algorithm that removes duplicated elements in a list
What is the ocf for this project : The project is estimated to generate $3,250,000 in annual sales, with costs of $2,270,000. If the tax rate is 22 percent, what is the OCF for this project
Determine each project payback and NPV : The cost of capital is 10%, and Garneau usually requires projects to have a payback within four years. Determine each project's payback and NPV
Programming exercise - tayler expansion : Programming Exercise - Tayler expansion - how to determine whether a particular number is a prime number. In this learning activity
What is the contribution margin per unit and ratio : The accountant has provided Tupac with the following data to prepare next year's campaign. What is the contribution margin per unit and ratio for 2022

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd