-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6418 from jelambrar96/jelambrar96_reto_36_python
Reto #36 - Python
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
Retos/Reto #36 - PERMUTACIONES [Media]/python/jelambrar96.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
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() | ||
|
||
|