I have the below code for a card game, it should remove the N number of cars from the given card list and return a tuple with 2 lists, the first list is the N objects from the original list and the secons list is the remaining cards not extracted from the original list.
lista_cartas = [1,2,3,4,5,6,7,8]
lista_N = []
N = 5
for i in range(N):
extracto = lista_cartas.pop(0)
lista_N.append(extracto)
lista_final = [lista_N, lista_cartas]
print(tuple(lista_final))
([1, 2, 3, 4, 5], [6, 7, 8])
it's working as I want but I need to trasform this into a function that takes the N number and the list as parameters, how can I achieve this?
is this somethinhg valid? or how can I make the function to take a list?
def sacar_cartas(N, lista=[]):
for i in range(N):
extracto = lista_cartas.pop(0)
lista_N.append(extracto)
lista_final = [lista_N, lista_cartas]
print(tuple(lista_final))