Posts by Leafar • 173 points
7 posts
-
1
votes4
answers140
viewsA: How to print more than a maximum number of a list
A way to do that is the following: aluno = ["alice", "bob", "carol", "dave", "eve"] notas = [10, 7, 9, 10, 10] maiores_notas = [aluno[i] for i in range(len(aluno)) if notas[i] == max(notas)] That…
-
0
votes2
answers133
viewsA: How to create two y points for a same x?
Well, the main problem is that you are using the list index to 'save' the value x, but this is not possible when you have two elements with the same value x, since the list soh can have a value y…
-
0
votes1
answer100
viewsA: How to remove repeated values from a dictionary?
This can be done with a single command as follows: from collections import Counter B = {k: A[k] for k in A if Counter(A.values())[A[k]] == 1}
-
1
votes1
answer39
viewsA: Program does not count points in the correct way
In that if internal, you are comparing all responses of a student with the same content of the feedback, instead of comparing each response with a different content of the feedback: /*Compara a…
-
1
votes1
answer142
viewsA: How to create an Array within the other
To put a list inside another list, just use the method append in the external list with the internal list as a parameter. a = [] for _ in range(10): a.append([1, 2, 3]) # Lista a agora contém 10…
-
1
votes1
answer220
viewsA: Add tuple in Python set
Well, there are two mistakes you’re making: You’re iterating over the dictionary keys unnecessarily. In the first code, this causes you to add the new edge to all the graph nodes (and note that you…
-
0
votes3
answers211
viewsA: Compare the widget with the rest of the Python list
You can use a dictionary to save how many times a name has appeared. names = ['eduardo', 'joao', 'eduardo', 'eduardo', 'joao'] d = {} for i in range(len(names)): if names[i] in d: d[names[i]] += 1…