List dictionary, tour Python values

0

I want to go through a dictionary that has lists within

Lista = {'829690':['testmartin','--test$2--']}

I need that in my function For key in ... read me testmartin and --test$2--

Here is everything I have to do with the key0 and I need the same thing to be repeated for each key in the dictionary:

for lista in Lista.itervalues():
    for value in lista:
        nombre.send_keys(value)
        try:
            element_present = EC.presence_of_element_located((By.CSS_SELECTOR, '.select2-results-dept-0'))
            WebDriverWait(driver, timeout).until(element_present)
        except TimeoutException:
            print ("Timed out waiting for page to load")
        nombre2 = driver.find_element_by_css_selector('.select2-results-dept-0').click()
    driver.find_element_by_css_selector('button.btn-success:nth-child(3)').click()
    try:
        element_present = EC.presence_of_element_located((By.CSS_SELECTOR, "div.modal-footer:nth-child(3) > button:nth-child(1)"))
        WebDriverWait(driver, timeout).until(element_present)

    except TimeoutException:
        print ("Timed out waiting for page to load")
    driver.find_element_by_css_selector('div.modal-footer:nth-child(3) > button:nth-child(1)').click()
    
asked by Martin Bouhier 19.10.2017 в 00:22
source

1 answer

1

You can not use indexes on a dictionary because by definition there is no order. The dictionary is accessed through its keys:

for key in Lista:
    nombre.send_keys(Lista[key])

If send_keys does not receive a list but must receive the two elements of this as arguments, use the operator * :

for key in Lista:
    nombre.send_keys(*Lista[key])

If you are not going to use the key at all you can iterate over the values:

  • Python 2:

    for value in Lista.itervalues():
        nombre.send_keys(*value) 
    
  • Python 3:

    for value in Lista.values():
        nombre.send_keys(*value)
    

Edit:

If you need to call the function for each value in the list then you need to iterate over it:

for lista in Lista.itervalues():
    for value in lista:
        nombre.send_keys(value)
    
answered by 19.10.2017 в 00:27