Shifting numbers in a list (Python3)
Go to solution
Solved by lewdicrous,
1 hour ago, Meic said:Frist to print without brackets use:
print(" ".join(lst))The to shift the other direction (you were almost there)
def shift_right(lst, n): return lst[-n:]+lst[:-n]Rather than passing the newlst to shift, I would recommend:
newlst = shift(lst, n)
Solution provided by @Meic
Note, the first code provided has been changed to make it work for my case, from:
print(" ".join(lst))
to:
print(" ".join(map(str, lst)))
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now