How do you set up a list of vocabularies with new keys?



  • There are two lists:

    a = [раз, два, три]
    b = [1, 2, 3]
    

    We need to set up a list of vocabularies.

    с = [{"word": 'раз', "count": 1}, {"word": 'два', "count": 2}, {"word": 'три', "count": 3}]
    

    Trying to use the cycle.

        spisok = []
        for word in a:
            for v in b:
                spis = {"word": wrd, "count": v}
            spisok.append(spis)
    

    But the "count" key values are the same for all the meanings of the "word" key, that's the last one on list b. Please tell me how to fix this problem.



  • Use the function. zip

    a = ["раз", "два", "три"]
    b = [1, 2, 3]
    c = []
    

    for word, count in zip(a, b):
    c.append({"word":word, "count":count})


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2