In Python, the elements in the list move forward one

Source: Internet
Author: User
Tags define function
Problem

Defines a one-dimensional array of type int, containing 10 elements, each assigned a value of 1~10, and then moving the elements in the array forward one 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.

Resolution (Python)

#!/usr/bin/env python#coding:utf-8def Ahead_one ():  a = [I for I in range]  B = A.pop (0)  a.append (b)  return AIF __name__ = = "__main__":  print Ahead_one ()

Settlement (Racket 5.2.1)

#lang racket; define function Ahead-one; Enter as an integer list int-list, assuming its length is N; The output is the same length as the integer list, whose nth-bit element is the 1th-bit element of int-list; The element of its 1~n-1 bit is the element of Int-list's 2~n bit (define (Ahead-one int-list) (Append (rest int-list) (list (first int-list))); function call, normal operation should output ' (2 3 4 5 6 7 8 9, 1) (Ahead-one (List 1 2 3 4 5 6 7 8 9 10))
  • Related Article

    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.