201
201
Extra
202
202
"""
203
203
204
- def word_analisis (word1 , word2 ):
204
+ def check (word1 : str , word2 : str ):
205
205
206
- words = [word1 , word2 ]
206
+ # Palíndromos
207
+ print (f"¿{ word1 } es un palíndromo?: { word1 == word1 [::- 1 ]} " )
208
+ print (f"¿{ word2 } es un palíndromo?: { word2 == word2 [::- 1 ]} " )
207
209
208
- for word in words :
209
- list_word = list (word )
210
- list_word .reverse ()
211
- reversed_word = "" .join (list_word )
210
+ # Anagramas
211
+ print (f"¿{ word1 } es anagrama de { word2 } ?: { sorted (word1 ) == sorted (word2 )} " )
212
212
213
- if word == reversed_word :
214
- print (f"La palabra { word } es Palíndroma\n " )
215
- print (word , "\n " )
216
- elif word != reversed_word :
217
- print (f"La palabra { word } es un Anagrama\n " )
218
- print (reversed_word , "\n " )
213
+ # Isogramas
219
214
220
- set_word = set (word )
221
- length = len (word )
215
+ def isogram (word : str ) -> bool :
222
216
223
- if len (set_word ) == length :
224
- print (f"La palabra { word } es un Isograma\n " )
225
- else :
226
- print (f"La palabra { word } no es un Isograma\n " )
217
+ word_dict = dict ()
218
+ for character in word :
219
+ word_dict [character ] = word_dict .get (character , 0 ) + 1
220
+
221
+ isogram = True
222
+ values = list (word_dict .values ())
223
+ isogram_len = values [0 ]
224
+ for word_count in values :
225
+ if word_count != isogram_len :
226
+ isogram = False
227
+ break
228
+
229
+ return isogram
230
+
231
+ print (f"¿{ word1 } es un isograma?: { isogram (word1 )} " )
232
+ print (f"¿{ word2 } es un isograma?: { isogram (word2 )} " )
233
+
234
+
235
+ check ("radar" , "pythonpythonpythonpython" )
236
+ # check("amor", "roma")
227
237
228
238
229
- word_analisis ("rallar" , "seder" )
230
- word_analisis ("caucasus" , "seder" )
231
- word_analisis ("caucasus" , "ambidiestramente" )
232
- word_analisis ("PUBVEXINGFJORD-SCHMALTZY" , "hola" )
239
+ check ("rallar" , "seder" )
240
+ check ("caucasus" , "seder" )
241
+ check ("caucasus" , "ambidiestramente" )
242
+ check ("PUBVEXINGFJORD-SCHMALTZY" , "hola" )
0 commit comments