This file contains hidden or 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
| st = list('gooogle') | |
| # ['g', 'o', 'o', 'o', 'g', 'l', 'e'] | |
| # Estamos iterando a lista "st" na ordem inversa ... | |
| for x in range((len(st)-1), (0-1), -1): | |
| print(st[x]) | |
| # Result | |
| e | |
| l |
This file contains hidden or 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
| nr = [100, 200, 300] | |
| # Acrescentando "10" à cada item, utilizando iteração "normal" | |
| for idx, item in enumerate(nr): | |
| nr[idx] += 10 | |
| # Resultado | |
| nr | |
| [110, 210, 310] |
This file contains hidden or 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
| # a) usando o COUNTER | |
| from collections import Counter | |
| t = 'gooogle' | |
| # o "Counter" recebe uma lista de elementos, e retorna qtas vezes cada elemento se repete, | |
| # no final ... apenas estamos transformando em um "dict" ... | |
| qtd = dict(Counter(list(t))) |
This file contains hidden or 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
| # a) USANDO ITERAÇÃO | |
| t = 'google' | |
| # a função SET() retorna apenas 1 vez cada elemento ... | |
| tu = set(t) | |
| # criammos uma "lista vazia" | |
| tl = [] |
This file contains hidden or 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
| # a) "dict.fromkeys(<lista>)", MANTENDO A ORDEM OS ELEMENTOS: | |
| lista = [1, 1, 2, 1, 3, 4, 3, 6, 7, 6, 7, 8, 10 ,9] | |
| lu = list(dict.fromkeys(lista)) | |
| # Resultado | |
| lu | |
| [1, 2, 3, 4, 6, 7, 8, 10, 9] |
This file contains hidden or 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
| def in_dictlist(key, value, my_dictlist): | |
| ''' | |
| Verify if an value is contained in a dictionary list. | |
| :param key: KEY where the VALUE will be searchead | |
| :param value: VALUE to be found | |
| :param my_dictlist: Dictionary where the search will be make it | |
| :return: TRUE if "value" (param) exists in "my_dictlist" (param) | |
| ''' |
This file contains hidden or 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
| # Normalmente não existe a necessidade de realizar ordenação em dicionários, haja vista | |
| # que acessamos um determinado "valor" através de uma "chave", ou seja ... não faz diferença | |
| # se essa "chave" esteja no INÍCIO ou no FIM do dicionário ... | |
| # definindo um dicionário ... | |
| d1 = {'um': 1, 'dois': 2, 'tres': 3, 'quatro': 4} | |