This article mainly introduces how to move the elements in the list one by one in python and the code that uses racket5.2.1 to implement this function.
Defines an int-type one-dimensional array, which contains 10 elements and is assigned to 1 ~ 10, and then move the elements in the array to a forward position,
That is, a [0] = a [1], a [1] = a [2],… The value of the last element is the value of the original first element, and then the array is output.
Solution (Python)
#! /Usr/bin/env python # coding: utf-8def ahead_one (): a = [I for I in range (10)] B =. pop (0). append (B) return aif _ name _ = "_ main _": print ahead_one ()
Solution (racket 5.2.1)
# Lang racket; defines the function ahead-one. the input is an integer list Of int-list, assuming its length is N. the output is a list of integers with the same length, the nth element is the 1st-bit element of the int-list; its 1 ~ The element of the N-1 bit is 2nd ~ of the int-list ~ (Define (ahead-one int-list) (append (rest int-list) (list (first int-list); function call, output during normal operation '(2 3 4 5 6 7 8 9 10 1) (ahead-one (list 1 2 3 4 5 6 7 8 9 10 ))