Mar-08-2018, 02:15 PM
How do I access the full list defined in another function with an api call that rather returns only a top 10 elements that starts with a given sub-string supplied to the api call in the current function.
I was wondering what would be the logic to apply here to get the full list through this rather limited window of the api call. The number of api calls must be as few as possible though for computation reasons.
def currentFunc(api): #function returns ['banana', 'bananas', 'ban'] but needs the whole lst ... #['apple', 'banana', 'bananas', 'ban', 'apple phone', 'apple ipad'] returned. lst = api('ba') #'ba' is chosen for demonstrating the function of api. return lst def listFunc(): lst = ['apple', 'banana', 'bananas', 'ban', 'apple phone', 'apple ipad'] api = lambda str: [l for l in lst if l.startswith(str)][:10] assert currentFunc(api) == lstSay our function in focus is CurrentFunc. This function has a parameter, api, passed as defined in the function listFunc. When any string is further passed to this api function, for instance, 'ba' it returns a maximum of 10 matching values from the list lst that start with 'ba' namely ['banana', 'bananas', 'ban']. But I want the function currentFunc return not just these values but the whole of 'lst' defined in the function listFunc.
I was wondering what would be the logic to apply here to get the full list through this rather limited window of the api call. The number of api calls must be as few as possible though for computation reasons.