Skip to content

Instantly share code, notes, and snippets.

@acwoss
Created May 28, 2018 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acwoss/a23289faaac514f2f480e18bf60a7e3c to your computer and use it in GitHub Desktop.
Save acwoss/a23289faaac514f2f480e18bf60a7e3c to your computer and use it in GitHub Desktop.
HeavenlyLightCensorware created by acwoss - https://repl.it/@acwoss/HeavenlyLightCensorware
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