1

I am using python 3.

for i in range(len(basic_elements)):
    value_list = [basic_elements[i], x_count[i]]

basic_element is a list of words, and x_count is a list of number. I want value_list to give me all the 50 elements in both lists together in value_list. But i kept on getting only the last element. I don't understand?!

Barmar
  • 669,327
  • 51
  • 454
  • 560
Sam H
  • 13
  • 2

1 Answers1

0

Doing the list assigment inside the loop re-initializes the list each time the loop is executed. I'm not entirely sure what you want your output list to look like, but something long the lines of

values_list = []
for i in range(len(basic_elements)):
    value_list.append((basic_elements[i], x_count[i]))

should create a list of basic_elements[i], x_count[i] tuples.

zyd
  • 539
  • 5
  • 15