![]() ![]() Now notice that I needed to add a pop to the variable since now it keeps the elements after the call to the function.Īlso I needed to use the nonlocal term so the function will know the cur variable. Yield from permutations_with_replacement_rec(n, m) Yield from permutations_with_replacement_rec(n_rec - 1, m_rec) This is how it turned out: def permutations_with_replacement(n: int, m: int) -> Iterator]:ĭef permutations_with_replacement_rec(n_rec: int, m_rec: int) -> Iterator]: Python 3 NumPy (builtin), 20 bytes lambda L:L.argsort() Try it online This one requires the input to be a numpy array. I created a sub function that is recursive taken out the cur variable. Python 3 NumPy (not using builtin), 29 bytes lambda L:sorted(L,em) Try it online This doesnt really use numpy except for the shorter item member which replaces the cumbersome getitem. ![]() So you said you do not like the way cur is implemented in your code, I thought of a way to take it out of the function declaration. Since it's a generator it should be: Iterator].
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |