Python moves the elements in the list forward one _python

Source: Internet
Author: User
Tags define function

Problem

Defines a one-dimensional array of int, contains 10 elements, assigns values to 1~10, and then moves 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-8

def ahead_one ():
  a = [I for I in Range (Ten)]
  B = A.pop (0)
  A.append (b) Return
  a

if __name__ = = "__main__":
  print Ahead_one ()

Resolution (Racket 5.2.1)

#lang racket

; define function Ahead-one
; Enter as an integer list int-list, assuming its length is N
; output is a list of integers of the same length, and its nth-bit element is the 1th-bit element of Int-list, 
  ; The element whose 1~n-1 bit is the 2~n bit of the Int-list
(define (Ahead-one int-list)
 (Append (rest int-list) (list (first int-list)) )

; function calls should output ' (2 3 4 5 6 7 8 9 1)
(Ahead-one (List 1 2 3 4 5 6 + 7 8 9 10)) in normal operation

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.