def answer(list): returnList = [] # returnt list is the list i'm compiling to return from the function value = "" # value is the string that i'm using to see if i've got a string of the same value like two that start with Y comparingList = ['z'] # comparingList is the list that i'm making to resend into the answer function so it can spit back a array of cappared values #the z is just here for a placeHolder to not trigger the bottom else for x in list: print(x) if value == x[0]: print("equal so where going to try some inferences") comparingList.append(x[1:]) #append everthing after the first decible else: if len(comparingList) != 1: #call answer #then add the values to the new list comparingList = [] else: value = x[0] comparingList[0] = x[1:] #this because if value == x[0] you need the previous value in comparingList returnList.append(x[0]) print(returnList) print(comparingList) answer(["z", "yx", "yz"])
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question