Question

Using Python. Write a function clean2(aList) that takes a list of integers aList as argument, and...

Using Python. Write a function clean2(aList) that takes a list of integers aList as argument, and modifies this list, such as multiple occurrences of values have been removed. The procedure does not return a list: it modifies its argument (reference aList). 3 For instance, the following statements: al = [1,2,3,4,4,4,5,1,2,1,5] print(al) clean2(al) print(al) print the following result (a different order of values is acceptable): [1,2,3,4,4,4,5,1,2,1,5] [1,2,3,4,5]

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def clean2(aList):
    i = 0
    while(i<len(aList)):
        if aList.count(aList[i]) > 1:
            aList.remove(aList[i])
        else:
            i += 1

al = [1,2,3,4,4,4,5,1,2,1,5]
print(al)
clean2(al)
print(al)
Add a comment
Know the answer?
Add Answer to:
Using Python. Write a function clean2(aList) that takes a list of integers aList as argument, and...
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
  • Write a function maxList that takes in a list of integers as argument and returns their...

    Write a function maxList that takes in a list of integers as argument and returns their highest. You may not use the max() or the sorted() Python built-in functions.

  • write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple

    1 write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple. Hint (can be done in one pass, you are not allowed to use built-on min and max functions.)max, min = find_max_min(my_list):2 write a Python function that takes in a list of integers (elements), and an integer number (num). The functions should count and return number of integers in elements greater than, less than, and equal to...

  • Write a function that takes, as an argument, a list of positive integers and a target...

    Write a function that takes, as an argument, a list of positive integers and a target value, and returns the number of times that the target value appears in the list. Call this function problem1(myList, target). For example, >>>problem1([1,2,3,4,5,6,5,4,3], 5) should return 2, and >>>problem1([1,2,3,4,5,6,5,4,3], 7) should return 0.

  • IN PYTHON: Write a function that takes, as an argument, a positive integer n, and returns...

    IN PYTHON: Write a function that takes, as an argument, a positive integer n, and returns a LIST consisting of all of the digits of n (as integers) in the same order. Name this function intToList(n). For example, intToList(123) should return the list [1,2,3].

  • Haskell Function program Write a function negateOdds that takes a list of integers and returns a...

    Haskell Function program Write a function negateOdds that takes a list of integers and returns a list of integers with all of the odd integers negated. negateOdds :: [Integer] -> [Integer] example: [1,2,3,4,5] should return [-1,2,-3,4,-5]

  • aList = [1, 'Mercy', 20, 'Cyber', 300]. a) Write a single line of Python statement to...

    aList = [1, 'Mercy', 20, 'Cyber', 300]. a) Write a single line of Python statement to print the value 20 from aList. b) Write a single line of Python statement to print the character b from aList. c) Write a single line of Python statement to print erc from aList. d) Write a Python segment that print a sequence number starting from 1 followed by ")" and an element for each element of the list. Use a for loop and...

  • Python Write a function named minGap that takes in a list of integers and returns the...

    Python Write a function named minGap that takes in a list of integers and returns the minimum ‘gap’ between values in the list. The gap between two adjacent values in a list is defined as the second value minus the first value. For example, suppose we have the following list: [1, 3, 6, 7, 12] The first gap is between indices 0 and 1 and its value is 3 − 1 = 2. The second gap is 6 − 3...

  • Write a recursive function sum-odds that takes a non-empty list of integers

    in python Part I: Sum of Odd Integers Write a recursive function sum-odds that takes a non-empty list of integers as an argument and returns the sum of only the odd integers in the list. In class we explored a recursive function called rsum that recursively computes the sum of a list of integers use it as a model to get started. Your function must be recursive and must not use any loops

  • GOALI Using your text editor, write the function sumSquares(aList). The function takes a list as ninput...

    GOALI Using your text editor, write the function sumSquares(aList). The function takes a list as ninput and returns (not prints) the sum of the squares of the all the numbers which absolute value s divisible by 3. If an element in the list is not a number, the function should ignore the value and ontinue. When the function receives an input that is not a list, code should return an error message o the user. Hints: review the type) or...

  • For Python [25 pts] Write the method divisorList(aList, divisor) that takes in a list with elements...

    For Python [25 pts] Write the method divisorList(aList, divisor) that takes in a list with elements of any data type and a divisor which is in the form of an integer. The output is a sorted list of only the integers that are divisible by the divisor. Example: divisorList([1, 1, 12, 'a', 90, 34], 2) will return [12, 34, 90] since 12, 90, and 34 are all divisible by two. Note that the returned list is sorted from smallest to...

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