Question

def clean_up(l): '''list of str->list of str The functions takes as input a list of characters....

def clean_up(l):
'''list of str->list of str

The functions takes as input a list of characters.
It returns a new list containing the same characters as l except that
one of each characters that appears odd number of times in l is removed
and all the * characters are removed

>>> clean_up(['A', '*', '$', 'C', '*', '*', 'P', 'E', 'D', 'D', '#', 'D', 'E', 'B', '$', '#'])
['#', '#', '$', '$', 'D', 'D', 'E', 'E']

>>> clean_up(['A', 'B', '*', 'C', '*', 'D', '*', '*', '*', 'E'])
[]
'''

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def clean_up(l):
    '''list of str->list of str

    The functions takes as input a list of characters.
    It returns a new list containing the same characters as l except that
    one of each characters that appears odd number of times in l is removed
    and all the * characters are removed
    '''
    result = []
    for x in l:
        if (x!='*') and (l.count(x)%2==0):
            result.append(x)
    return result

# Testing
print(clean_up(['A', '*', '$', 'C', '*', '*', 'P', 'E', 'D', 'D', '#', 'D', 'E', 'B', '$', '#']))
print(clean_up(['A', 'B', '*', 'C', '*', 'D', '*', '*', '*', 'E']))

Add a comment
Know the answer?
Add Answer to:
def clean_up(l): '''list of str->list of str The functions takes as input a list of characters....
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
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