Skip to content

Commit

Permalink
Merge pull request #6418 from jelambrar96/jelambrar96_reto_36_python
Browse files Browse the repository at this point in the history
Reto #36 - Python
  • Loading branch information
kontroldev authored Mar 21, 2024
2 parents b0fc362 + c57b72c commit 91b3378
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Retos/Reto #36 - PERMUTACIONES [Media]/python/jelambrar96.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/python3

"""
Reto #36: Permutaciones
/*
* Crea un programa que sea capaz de generar e imprimir todas las
* permutaciones disponibles formadas por las letras de una palabra.
* - Las palabras generadas no tienen por qué existir.
* - Deben usarse todas las letras en cada permutación.
* - Ejemplo: sol, slo, ols, osl, los, lso
*/
"""

__author__ = "Jorge Lambraño - jelambrar96"
__copyright__ = "Copyright 2024, retos-programacion-2023"
__credits__ = ["Brais Moure - mouredev"]
__license__ = "GPL"
__version__ = "1.0.1"
__maintainer__ = "Jorge Lambraño"
__email__ = "[email protected]"
__status__ = "Production"


from itertools import permutations


def permutaciones_palabra(cadena: str):
return [ "".join(item) for item in permutations(cadena) ]

def mostrar_permutaciones_palabra(cadena: str, sep=' - ', end='\n'):
permutaciones = permutaciones_palabra(cadena)
print(*permutaciones, sep=sep, end=end)


if __name__ == '__main__':
palabras = ['hola', 'sol', 'love', 'roma']

for p in palabras:
print(p)
mostrar_permutaciones_palabra(p)
print()


0 comments on commit 91b3378

Please sign in to comment.