Hi,
I’m trying to implement a function that takes in 2 kwargs, like so:
sorted_with_kwargs(odd = [1,3,5], even = [2,4,6])
and returns a list, lst = [1,2,3,4,5,6]
I was able to do it without kwargs:
dct1 = {'odd': [1,3,5]}
dct2 = {'even': [2,4,6]}
def sorted(a,b):
lst = []
for i,j in zip(a.values(), b.values()):
for k,l in zip(i,j):
lst.append(k)
lst.append(l)
return lst
print(sorted(dct1, dct2))
output: [1,2,3,4,5,6]
I think I could just add to a list and then sort it using sort() method, but I’m curious if there’s a way of doing it without it.
By the way, that’s what I’ve got so far:
def sorted_with_kwargs(**kwargs):
lst = []
for i in kwargs.values():
for j in i:
lst.append(j)
return lst
Which returns:
[1,3,5,2,4,6]
Thanks!