Public feed #727373

Someone

public python v1 · immutable
Raw Edit
·published 2007-10-05 23:16 UTC
rendered paste body
def whereis(s1,s2):    '''whereis(str, str) - > int/boolean        Returns the index number of the first occurence of the single letter     string s2 in the string s1. Returns False if the parameters given are not     strings and if s2 is not a single letter in length.'''    if ( type(s1) != str ) or ( type(s2) != str ):        return False        if len(s2) != 1:        return False        return s1.find(s2)def reverse(original_list):    '''reverse(list) - > list/boolean        Given a list, returns a new list in which the elements of the original    list have been reversed. Returns False if the parameter given is not a list.     '''        if ( type(original_list) != list ) :        return False    new_list = []    for element in original_list:        new_list.insert(0,element)        return new_listdef fix_capitalization(original_list):    '''fix_capitalization(list) - > list/boolean        Given a list of strings returns a new list of strings in which the    capitalization of the original strings has been corrected. Returns False if    the parameter given is not a list.'''        if ( type(original_list) != list ):        return False         new_string = ''    for string in list:        for char in string:            if char == string[0]:                new_string = new_string+char #Leaves the first character in                 #the string unchanged.            else:                new_char = char.lower()                new_string = new_string + new_char #Changes all other characters                #in the string to lowercase.        new_string = new_string+' ' #Separates all of the strings         #by a single blank space.    new_list = new_string.split() #Splits the corrected strings into a new list.        return new_list