Created
February 16, 2022 19:46
-
-
Save antonioccneto/02964bc2cff49a81f3b984adf5589bbc to your computer and use it in GitHub Desktop.
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
# Contar total de itens em dicionários em uma lista | |
nomes = [] | |
total = [] | |
usuario = {} | |
lista = [{'user': 'João', 'idade': 25}, {'user': 'Maria', 'idade': 22}, {'user': 'João', 'idade': 33}] | |
for item in lista: | |
if not item.get('user') in nomes: | |
nomes.append(item.get('user')) | |
for user in nomes: | |
usuario = {'user': user, 'total': 0} | |
for item in lista: | |
if item.get('user')==user: | |
usuario['total'] += 1 | |
total.append(usuario) | |
print(total) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment