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

  Which function is used to receive input from users

In computation if operands of different types are involved, Python converts the operand with "smaller" type to the "larger" type. What is this called?

  Generate a modest web page via python flask

Generate a modest Web page via Python flask. It should include basic components of HTML. The Web page should have at least three Headings.

  Write a program that asks for the user age

Write a program that asks for the user's age. Based on their response print "You can vote" (18 years old or older) or "You can't vote" and also whether or not he/she is a senior citizen (over 64)

  Calculate and display the average of the 5 scores

Each gymnast in a competition receives scores from 5 judges. Write a Python program to do the following. calculate and display the average of the 5 scores.

  ITC106 Programming Principles Assignment

ITC106 Programming Principles Assignment Help and Solution, Charles Sturt University - Assessment Writing Service - Develop an additional system for storing

  Implements the binary tree as a class

Implements the binary tree above as a class. Divides into tokens, generating an iterator, with added support for variable names. Evaluates a postfix expression, given an iterator, with added support for variables.

  Write the function that draws car image with turtle graphics

Write the function draw_car that draws, with Turtle graphics, the car from the image that you can find at the end of the homework.

  Create a python script that takes two parameters

Create a Python script that takes two parameters. List all files names, size, date created in the given folder. Use catch-exception block.

  Create a pseuodcode to design a do-while loop

Create a pseuodcode to design a do-while loop that asks the user to enter two numbers. The numbers should be added and the sum displayed.

  Write a python simulation to experimentally verify problem

Write a Python simulation to experimentally verify the Monty Hall problem. Your simulation should run a large number of trials for two scenarios.

  Write a function long strings that has one argument

Write a function long strings that has one argument- file name that is a string that is the name of a text file.The file will consist of a number of lines.

  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.

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