0

I have a python script that does the following task. It does a for loop to go through the array items and gives relevant information belonging to that item.

I want to update the array in real-time and also the for loop must be executed without resetting. Some ML training happens inside the for loop so it should not be restarted whenever the array get updated. At the same time the for loop must be able to detect the appended items in the array.

'''

arr = [a,b,c]
for i in arr:
    print(i)     #and do something

Now basically the arr will be appended by listening to a DB column. For instance, i do

arr.append(dbData)

I know I can use the function to call the for loop again, but how to do it without having to reset the loop?

Thank you for your help. Kindly let me know if the question is unclear.

1

2 Answers 2

0

See also here

You create an iterator over the list and add to it as needed

arr = [a,b,c]
for i in arr:
    print(i) 

islice(arr,0,len(arr)-1)

Check out this tutorial for a good intro on how to use the islice method

Sign up to request clarification or add additional context in comments.

Comments

0

I am not kind of sure about islice iterator. The following code gave me the right outputs.

myarr = [1,2,3]
bb = []
while True:
    for a in myarr:
        if len(myarr)==3: #some condition
            bb.append(4)
            myarr.extend(bb)
        print(a, myarr)

Thanks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.