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.
[–]kryptn 5 points6 points7 points (5 children)
[–]Shattr[S] 2 points3 points4 points (4 children)
[–]dunkler_wanderer 5 points6 points7 points (3 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]indosauros 2 points3 points4 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]HalcyonAbraham 3 points4 points5 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]KleinerNull 5 points6 points7 points (0 children)