Skip to content

Instantly share code, notes, and snippets.

@hmbr
Created November 16, 2011 16:35
Show Gist options
  • Save hmbr/1370579 to your computer and use it in GitHub Desktop.
Save hmbr/1370579 to your computer and use it in GitHub Desktop.
sample.py
#!/usr/bin/env python
def adicionando(novo, lista, max=None):
retorno = [[novo]]
for i in lista:
retorno.append(i)
resposta = i[:]
resposta.append(novo)
if (max is None or len(resposta) <= max):
retorno.append(resposta)
return retorno
def criar_grupos(lista, max=None):
if (len(lista) > 1):
return adicionando(lista[0], criar_grupos(lista[1:], max), max)
return [lista]
def main():
for i in criar_grupos(range(1, 5), 2):
print ' '.join(str(n) for n in i)
if __name__ == '__main__':
main()
@hmbr
Copy link
Author

hmbr commented Nov 16, 2011

mais um
real 0m0.028s
user 0m0.016s
sys 0m0.008s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment