Created
May 28, 2018 13:42
-
-
Save acwoss/a23289faaac514f2f480e18bf60a7e3c to your computer and use it in GitHub Desktop.
HeavenlyLightCensorware created by acwoss - https://repl.it/@acwoss/HeavenlyLightCensorware
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
def flatten(data): | |
""" Representa uma lista|tupla multiníveis de maneira plana. | |
Parâmetros: | |
data (list|tuple): Iterável com as informações a serem planificadas. | |
Retorno: | |
Retorna um gerador com os dados de entrada em sua forma plana. | |
Exemplo: | |
>>> data = ['anderson', ['carlos', ['woss']]] | |
>>> list(flatten(data)) | |
['anderson', 'carlos', 'woss'] | |
""" | |
for item in data: | |
if isinstance(item, (list, tuple)): | |
yield from flatten(item) | |
else: | |
yield item | |
strings = [ | |
'anderson', | |
[ | |
'carlos', | |
[ | |
'woss', | |
'stackoverflow' | |
] | |
] | |
] | |
maior_string = max(flatten(strings), key=len) | |
print(f'O maior texto encontrado foi: {maior_string}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment