-1

I am having trouble storing multiple float values and adding them to a list to let it expand. I am getting the error "'float' object is not iterable"...

while True:

    #some code here

    value_list = [value]
    value_list.extend(value)
    print("saving list", value_list)
    print("max", max(price_list))

    time.sleep(600)

value is scraping data from a website that I own with certain prices and it is converting it to float and the shared code is in a while True statement to show if the price changes overtime, then I want it to display the highest value from the stored list.

ghost
  • 29
  • 1
  • 7
  • `extend()` expects an itterable like a list or tuple. If you just want to add a single value, use `append()`. – Mark Feb 22 '21 at 02:46
  • Hi Mark! That's exactly what I am looking for to add each value to regardless if it is the same to the list. It as updating the current value to the list and not the previous ones, therefore, the list is not expanding! :( – ghost Feb 22 '21 at 02:49
  • 1
    You are defining a new `value_list` list in each iteration of the loop. If that is supposed to be one list that expands during the loop, you need to define it outside the `while` loop. – Mark Feb 22 '21 at 02:50

1 Answers1

1

As suggested in the comment, you would do something like this:

value_list = []

while True:

    #some code here

    value_list.append(value)
    print("saving list", value_list)
    print("max", max(price_list))

    time.sleep(600)
Nerveless_child
  • 1,366
  • 2
  • 15
  • 19