Skip to content

Instantly share code, notes, and snippets.

@gustavopinto
Created November 6, 2011 15:10
Show Gist options
  • Select an option

  • Save gustavopinto/1343004 to your computer and use it in GitHub Desktop.

Select an option

Save gustavopinto/1343004 to your computer and use it in GitHub Desktop.
search list
input = [1,4,1,4,6,5,5,5,4,2,3]
predicate = [1,3,5]
output = []
def init():
for i in predicate:
if input.count(i) > 0:
output.append([getandpop(i) for row in range (0, input.count(i))])
print output
def getandpop(element):
try:
ind = input.index(element)
input.pop(ind)
input.insert(ind, -1)
return ind
except ValueError:
pass
if __name__ == "__main__":
init()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment