Created
November 16, 2011 16:35
-
-
Save hmbr/1370579 to your computer and use it in GitHub Desktop.
sample.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
novo codigo
real 0m0.023s
user 0m0.016s
sys 0m0.004s
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
time ./range.py
....
real 0m0.037s
user 0m0.016s
sys 0m0.016s