1
How do I make sure that, in the following code, the values that show the position where x is repeated are each one per line? Except for the clasp and comma.
from collections import defaultdict
n = int(input(''))
vetor = []
for c in range(n):
if n >=1 and n <= 100:
vetor.append(int(input()))
x = int(input(''))
if x in vetor:
repete = vetor.count(x)
print(repete)
posições = defaultdict(list)
for i, x in enumerate(vetor):
posições[x].append(i)
for x in posições:
if len(posições[x]) > 1:
print(str(posições[x]).strip('[]'))
Assuming my N is 5, my list is 2,2,2,3,2 and x is 2, the output is being that:
4 #numero de vezes que o X se repete
0,1,2,4 #posições que o X se encontra repetido
Purpose of the code is what? It’s very confusing. But I’ll take the risk that it’s checking repeated numbers on a list, but there are some restrictions (looking at the code), it looks like an exercise...
– William Teixeira
I need to make a set of size N , after that, give the N values. With this, I need to make an X that I put is identified in the set, then it is necessary that I speak how many times it repeats (thing I was able to do) and in which positions it repeats. Everything has to be on different lines in the output.
– Gabriel Schrader