I want to find the difference between the last element and the second last element of the array where the array changes dynamically.
Please go through the code.
import requests
import json
from bs4 import BeautifulSoup as bs
import datetime, threading
LTP_arr=[]
url = 'https://nseindia.com/live_market/dynaContent/live_watch/get_quote/GetQuoteFO .jsp?underlying=RELIANCE&instrument=FUTSTK&expiry=30MAY2019&type=-&strike=-'
def ltw():
resp = requests.get(url)
soup = bs(resp.content, 'lxml')
data = json.loads(soup.select_one('#responseDiv').text.strip())
LTP=data['data'][0]['lastPrice']
LTP_arr.append(LTP)
print(LTP_arr)
threading.Timer(1, tvwap).start()
ltw()
At a particular time if the array is LTP_arr=['34','65','66','32','81'] Output should be given as 49. Then on next time frame if the LTP_arr=['34','65','66','32','81','100'] output sholuld be shown as 19
ltw()? Your code is very poorly formatted. However, useint(LTP_arr[-1])-int(LTP_arr[-2]). Surround the expression withabs()if you want the absolute value.