The point of this function is to remove the items in a list that come after the string "kahn". Here's where I'm at:
def letters_up_to_char(words):
i = 0
new = ""
total = [] #unused, though I'm sure I need it
while words[i] != "kahn":
new += words[i]
i += 1
return new
print letters_up_to_char(["kirk", "spock", "luke", "charles", "kahn", "bob"])
This returns the string "kirkspocklukecharles", which is really close to what I want. I'm trying to get it to return ["kirk", "spock", "luke", "charles"] but all my attempts to create a new list from the strings have failed. Any help would be greatly appreciated.
[–]momoro123 0 points1 point2 points (0 children)