In python, move the elements in the list one by one

Source: Internet
Author: User
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 ))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.