I am testing a set of web apis, using python, a language I am still in the process of learning. I am taking in a string, the name of a dealer, and chopping off the end after a random number of characters. I am then adding a character (wild card) to then end of the string. That modified string is then passed to an api that searches for the name of a dealer, and can include wild cards. I have the code below, but it seems long. Is there a cleaner looking, or more pythonic way of approaching this problem? Potentially a way to do this without converting from a string, to a list, back to a string?
split_name = list(name) #turns name string into list
rand = random.randint(6,(len(split_name)-1)) #generates random number
split_name[rand:len(split_name)] = [] #breaks of end part of name list
srch_name = ''.join(split_name) #stringifies list
#Send request
rqst = requests.get(name_srch %(key, (srch_name + '*'))) #this adds * and sends the request
Name is earlier defined in the script to be some string, such as "Dave and Bills equipment sales and service, INC" I should note I am using python 2.7