I have this dictionary:
db= {'www.baurom.ro':
{0: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
1: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
},
'slbz2':
{0: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
1: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
}
And the list:
lista=['www.baurom.ro', 'www.baurom.ro', 'www.baurom.ro', 'www.baurom.ro', 'www.baurom.ro', 'www.baurom.ro', 'www.baurom.ro', 'www.listafirme.ro', 'www.romanian-companies.eu', 'www.risco.ro']
What am I doing now:
for x in lista:
if x in db:
db[x][0][lista.index(x)]+=1
In other words, I want to calculate how many times each site appears in the list and at what position. This works, but in this example it will return something like:
{0: [7, 0, 0, 0, 0, 0, 0, 0, 0, 0]
while I would like it to be:
{0: [1, 1, 1, 1, 1, 1, 1, 0, 0, 0]
How can i achieve this? I can use a variable, initiate it with var = 0 and then + = 1 and use it as an artificial index, but is there a more βpythonicβ way to do this?