I am trying to create my first function using kwargs and I'm having some trouble with the looping.
I am passing two kwargs: tick and start. Both tick and start are going to be strings or lists of strings.
I want to loop through the kwargs to categorize them using if elif and contain with the proper string and the kwarg
when the kwarg passes the test I want to take that kwarg's values and append it/them to the list matching its name list (ie. tick goes into tick list)
At the moment I am taking all the kwargs values and appending them to the list not the kwarg's value that I am working on.
There is a distinction between kwarg, kwargs and kwarg's sorry it that is confusing.
def fn1(**kwargs):
ticks = []
start = []
# Iterating over the Python kwargs dictionary
for kwarg in kwargs: # For each kwarg in kwargs
if "ticks" in kwarg: #Test if "tick" in kwarg. If yes continue to line below, if not skip the next two lines
for kwarg in kwargs.values(): #for each i in kwargs values THIS IS WRONG
ticks.append(kwarg)
break # I use this to fix what is wrong
elif "start" in kwarg:
for kwarg in kwargs.values(): #Same problem as 5 lines up, and now I do not know how to either skip the first iteration of the loop or fix the original problem
start.append(kwarg)
print(ticks, start)
Input:
fn1(ticks= ["IBM", "AAPL"], start= "2")
Output:
[['IBM', 'AAPL']] [['IBM', 'AAPL'], '2']
Desired Output:
[['IBM', 'AAPL']] ['2']