So I started learning python in my free time, because of covid. Yesterday I tried creating a function that converts two arguments into one list and combines them. For example I created a function: sumup((1,2,3),(4,5,6)) that returns [1, 2, 3, 4, 5, 6]. This was fairly easy to do.
def sumup(arg1, arg2):
combine_1 = list(arg1 arg2)
return combine_1
But now im trying to figure out how I can combine tuples and lists. So sumup((1,2,3), [565]) should return [1,2,3,565].
I'd be glad if someone could give me some hints.
CodePudding user response:
I am not sure if this is what you want to accomplish, but at a glance, I would suggest that you convert your tuple to a list in order to concatenate both lists. Here is an illustration:
def merge_tuple_and_list(tuple, mlist):
return np.concatenate([list(tuple), mlist])
print(merge_tuple_and_list((1,2,3), [565]))
print(type(merge_tuple_and_list((1,2,3), [565])))
Output:
array([ 1, 2, 3, 565])
<class 'numpy.ndarray'>