I must find a way to get the item position when iterating over a list using a for structure
other_list = ["line1", "line2", "line3", ... , "line125k+"]
#contains 125k+ items from a txtFile.readlines()
list = ["item1", "item2", "item3"]
#contains 35 items
dict = {"key1":["value1"], "key2":["value2"], "key3":["value3"]}
#contains 35 items too
For each value inside my dict, i got a key that have a correspondent item in the list.
list = ["10", "20", "30"]`
dict = {"19":["value1"], "29":["value2"], "39":["value3"]}
the dict's first key, "19", corresponds to the "10" inside the other list..
Example:
dict[0] corresponds to list[0]
dict[1] corresponds to list[1]
... and so on.
So i have to get the item position while using a for structure, so then i can access the correspondent key in the dict, and use the dict's value in a replace()
#replace tax1 value
for item in list:
pos_item = item.getPosition() # pos_item = getIteratorValue()
#how can i assign the dict value to a variable?
dict_value = dict[pos_item][value]
#use one variable to search and the other as a replacement
other_list[pos_item].replace("0,00", dict_value)
OrderdDictinstead of adictor sort your dict items and work with the sorted result which is not a dictionary anymore and is a list!enumerate(), to find out the current position in the iteration . Obviously, using index won't allow to get dict's items