Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a function partition() that takes a list of strings and a character as

ID: 639474 • Letter: 1

Question

1. Write a function partition() that takes a list of strings and a character as parameters. It prints the strings in the list that begin with a letter at or after the character (according to dictionary order), one per line. The capitalization of the character and the first letter of the string should not make a difference in whether the string is printed. Empty strings should be skipped. You may assume that the character given as the second parameter is an upper- or lowercase letter. The following shows several sample runs of the function:

Explanation / Answer

definition of function partition():

def partition(array=[], x=''):

   

    for i in range(len(array)):

        if ' ' in array[i]:

            print

        if array[i][0].lower()==x.lower():

            print(array[i])

        else:

            if x.lower() not in array[i].lower():

                    print(array[i])

partition(['djengo', 'AMBER','Cookie','Sarah','erin'],'b')

Sample output:
sh-4.2# python main.py                                  

djengo                                                  

Cookie                                                  

Sarah                                                   

erin  

---------------------------------------------------------------------------------

partition(['djengo', 'AMBER','Cookie','Sarah','erin'],'b')

Sample output:

sh-4.2# python main.py                                  

djengo                                                  

Cookie                                                  

Sarah                                                   

erin  

------------------------------------------------------------------------------------------

   

def partition(array=[], x=''):   

    for i in range(len(array)):

        if ' ' in array[i]:

            print

        if array[i][0].lower()==x.lower():

            print(array[i])

        else:

            if x.lower() not in array[i].lower():

                    print(array[i])

partition(['Bob', 'Mary','Zee',' '],'W')

Sample output:

sh-4.2# python main.py                                  

Bob                                                     

Mary                                                    

Zee

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote