Python: searching methods

7.4.1. Contar cantidad de apariciones elementos

Método: count(elemento)

>>> nombres_masculinos = ["Alvaro", "Miguel", "Edgardo", "David", "Miguel"] 
>>> nombres_masculinos.count("Miguel") 
2
 
>>> nombres_masculinos = ("Alvaro", "Miguel", "Edgardo", "David", "Miguel") 
>>> nombres_masculinos.count("Miguel") 
2

7.4.2. Obtener número de índice

Método: index(elemento[, indice_inicio, indice_fin])

>>> nombres_masculinos.index("Miguel") 
1 
>>> nombres_masculinos.index("Miguel", 2, 5) 
4

SOURCEhttp://librosweb.es/libro/python/capitulo_7/metodos_de_busqueda_2.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s