1+ # Cadenas de caracteres
2+
3+ string = "Hola Python"
4+ string2 = "Como estan?"
5+
6+ # Concatenacion
7+ print (string + ", " + string2 )
8+
9+ # Repeticion
10+ print (string * 3 )
11+
12+ # Acceso a caracteres especificos
13+ print (string [2 ])
14+
15+ # Slicing
16+ print (string [:5 ])
17+
18+ # Longitud
19+ print (len (string2 ))
20+
21+ # Busqueda
22+ print ('a' in string )
23+ print ('h' in string2 )
24+
25+ # Conversion a mayusculas, minusculas y primera letra en mayusculas
26+ print (string .upper ())
27+ print (string .lower ())
28+ print (string2 .title ())
29+ print ("me llamo nacho" .capitalize ())
30+
31+ # Remplazo
32+ print (string .replace ("a" , "5" ))
33+
34+ # Division
35+ print (string2 .split ("o" ))
36+
37+ # Eliminacion de espacios al principio y al final
38+ print (" hola mi nombre es nacho " .strip ())
39+
40+ # Encontrar
41+ print (string .find ("P" ))
42+
43+ # Busqueda al principio y al final
44+ print (string .startswith ("h" ))
45+ print (string .endswith ("n" ))
46+
47+
48+ # Busqueda de ocurrencias
49+ print (string .count ("o" ))
50+
51+ # Formateo
52+ print ("AAAA {} texto sin sentido. {}" .format (string , string2 ))
53+
54+ # Interpolacion
55+ print (f"Viva molotov, { string2 } " )
56+
57+ # Transformacion en lista de caracteres
58+ caracters = list (string )
59+
60+ # Transformaciones numericas
61+ s1 = "12131341"
62+ s1 = int (s1 )
63+
64+ s2 = "1.5"
65+ s2 = float (s2 )
66+
67+ # Transformacion de lista en cadena
68+ lista = ["Hola" , "Python" , "Weyes" ]
69+ print (" " .join (lista ))
70+
71+ # Comprobaciones
72+ print (string .isalnum ())
73+ print (string .isalpha ())
74+ print (string .isascii ())
75+ print (string .isdecimal ())
76+ print (string .isdigit ())
77+ print (string .islower ())
78+ # Etc..
79+
80+ # Ejercicio extra
81+
82+ def check (word1 : str , word2 : str ):
83+
84+ # Palindromos
85+ print (f"{ word1 } es un palindromo?: { word1 == word1 [::- 1 ]} " )
86+ print (f"{ word2 } es un palindromo?: { word2 == word2 [::- 1 ]} " )
87+
88+ # Anagramas
89+ print (f"{ word1 } es un anagrama de { word2 } : { sorted (word1 ) == sorted (word2 )} " )
90+
91+ # Isograma
92+ def isogram (word : str ) -> bool :
93+
94+ word_dict = {}
95+ for character in word :
96+ word_dict [character ] = word_dict .get (character , 0 ) + 1
97+
98+ isograma = True
99+ values = list (word_dict .values ())
100+ isagram_len = values [0 ]
101+ for word_count in values :
102+ if word_count != isagram_len :
103+ isograma = False
104+ break
105+ return isograma
106+
107+ print (f"{ word2 } es un isograma? { isogram (word2 )} " )
108+ print (f"{ word2 } es un isograma? { isogram (word2 )} " )
109+
110+
111+ check ("radar" , "Python" )
112+ check ("amor" , "roma" )
0 commit comments