Question
please use basic programming language and explain with comment lines .for Thonny(python) format.
Duplicate elimination Create a function named unique that receives a list and returns a (possibly shorter) list containing on
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1 - def unique(a): result = [] for one in a: # looping through each item if one not in result: # if the item is not in the re

OUTPUT

Original list of numbers [11, 11, 2, 2, 7, 7, 5, 5, 3, 3] new list after calling unique function [2, 3, 5, 7, 11] Original li

CODE TO COPY

def unique(a):
  
result = []
  
for one in a: # looping through each item
  
if one not in result: # if the item is not in the result list
  
result.append(one) # putting it in the list
  
result.sort() # sorting the result
  
return result # returning
  
# sample runs
x = [11, 11, 2, 2, 7, 7, 5, 5, 3, 3]
print("Original list of numbers\n",x)
print("new list after calling unique function\n",unique(x))

x = ['red', 'red', 'orange', 'orange', 'yellow', 'yellow', 'green', 'green']
print("Original list of numbers\n",x)
print("new list after calling unique function\n",unique(x))

# Please up vote

Add a comment
Know the answer?
Add Answer to:
please use basic programming language and explain with comment lines .for Thonny(python) format. Duplicate elimination Create...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ** Language Used : Python ** PART 2 : Create a list of unique words This...

    ** Language Used : Python ** PART 2 : Create a list of unique words This part of the project involves creating a function that will manage a List of unique strings. The function is passed a string and a list as arguments. It passes a list back. The function to add a word to a List if word does not exist in the List. If the word does exist in the List, the function does nothing. Create a test...

  • A school teacher has a list of leftover school supplies from previous semesters. The teacher woul...

    A school teacher has a list of leftover school supplies from previous semesters. The teacher would like to maintain an ordered list of the supplies. Write a program in C that reads in the data (a list of supplies in random order) from a file, orders the items by name, and writes the ordered list to the output file. Assume the input file has the format of color (one word string), name, followed by quantity (int) with each type of...

  • JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class....

    JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class. Print out the results after testing each of the methods in both of the classes and solving a simple problem with them. Task 1 – ArrayList Class Create an ArrayList class. This is a class that uses an internal array, but manipulates the array so that the array can be dynamically changed. This class should contain a default and overloaded constructor, where the default...

  • Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int...

    Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int *a2) Write a program addition.c that reads in an array (a1) of numbers, and creates a new array (a2) of numbers such that the first and last numbers of a1 are added and stored as the first number, the second and second-to-last numbers are added and stored as the second number, and so on. You need to check for even and odd length of...

  • IN PYTHON 3 LANGUAGE, please help with function, USE RECURSION ONLY def im(l: 'an int, str,list,tuple,set,or...

    IN PYTHON 3 LANGUAGE, please help with function, USE RECURSION ONLY def im(l: 'an int, str,list,tuple,set,or dict') -> 'an int, str, tuple, or frozenset'      pass    SAMPLE OUTPUT: The following call (with many mutable data structures) imm(1)   returns 1 imm('a') returns 'a' imm( (1, 2, 3))   returns (1, 2, 3) imm( frozenset([1, 2, 3]))   returns frozenset({1, 2, 3}) imm( [1, 2, 3, 4, 5, 6])   returns (1, 2, 3, 4, 5, 6) imm( [1, 2, [3, [4], 5], 6])  ...

  • Please use comment headers to specify what each section of code does. The programming language is...

    Please use comment headers to specify what each section of code does. The programming language is C. Skeleton code: Sample output: Obiectives 1. To learn how to write functions given specifications 2. To learn how to the use pass by value and pass by reference variables 3. Review previous concepts like if-statements and loops. Movies about dragons and dragon training were very popular this summer. Your fiend has not stopped talking about how awesome dragons are and how cool it...

  • Microsoft Excel VBA (Visual Basic for Applications) Programming Language Objectives: Create an array and redim it...

    Microsoft Excel VBA (Visual Basic for Applications) Programming Language Objectives: Create an array and redim it to a size equal to an assigned value of a variable, populate the array with a series of random numbers, output the array to a message box and to a worksheet. Instructions: - Review the variables already declared. You won't need others. - See comments in the code that will act as your guide. Add new code directly after each comment. - Assign a...

  • computer science . the programming language is python

    11.9 LAB*: Program: Data visualization(1) Prompt the user for a title for data. Output the title. (1 pt)Ex:Enter a title for the data: Number of Novels Authored You entered: Number of Novels Authored(2) Prompt the user for the headers of two columns of a table. Output the column headers. (1 pt)Ex:Enter the column 1 header: Author name You entered: Author name Enter the column 2 header: Number of novels You entered: Number of novels(3) Prompt the user for data points. Data points must be in this format: string, int. Store the information before the comma into a string variable and the information after the comma into an integer. The user will enter -1 when they...

  • Can someone code this asap? Use any language that you want. 2. Ancestral Names Given a...

    Can someone code this asap? Use any language that you want. 2. Ancestral Names Given a list of strings comprised of a name and a Roman numeral, sort the list first by name, then by decimal value of the Roman numeral. In Roman numerals, a value is not repeated more than three times. At that point, a smaller value precedes a larger value to indicate subtraction. For example, the letter I represents the number 1, and Vrepresents 5. Reason through...

  • PYTHON 3 node Node ADT Question. Question 3 (18 points): Purpose: To practice working with node chains created using...

    PYTHON 3 node Node ADT Question. Question 3 (18 points): Purpose: To practice working with node chains created using the Node ADT to implement slightly harder functionality Degree of Difficulty: Moderate to Tricky In this question you'll implement merge sort for node chains! Recall, merge sort is a divide-and-conquer technique that uses recursion to sort a given sequence (in this case a node chain). A overview of the algorithm is given below. Algorithm mergeSort (NC) Borts node chain NC using...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT