[Python] A program that rotates the contents of the list to the left

[Python] A program that rotates the contents of the list to the left

This is a memo for myself.

▼ Question

--Rotate the contents of list to the left by the specified integer.

URL

▼sample input

python


a=[1,2,3,4,5]
d=4

▼sample output

python


[5, 1, 2, 3, 4]

▼my answer

python


def rotLeft(a, d):
    c = a[d:]
    d = a[0:d]
    return c+d

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')
    nd = input().split()
    n = int(nd[0])
    d = int(nd[1])
    a = list(map(int, input().rstrip().split()))
    result = rotLeft(a, d)
    fptr.write(' '.join(map(str, result)))
    fptr.write('\n')
    fptr.close()

## I was addicted to When I joined the list with the extend method, the return value became None.

python


a=[1,2,3,4,5]
c =a[4:]
d =a[0:4]

print(c.extend(d))

#Becomes None.

As far as I googled, it seemed that I could combine with the extend method, but ...

I would be grateful if you could tell me the reason.

Recommended Posts

[Python] A program that rotates the contents of the list to the left
[Python] A program that calculates the number of socks to be paired
[Introduction to Python] How to sort the contents of a list efficiently with list sort
[Python] A program that counts the number of valleys
[Python] A program that compares the positions of kangaroos.
A Python script that compares the contents of two directories
How to connect the contents of a list into a string
[Python] A program that rounds the score
A story that struggled to handle the Python package of PocketSphinx
[python] A note that started to understand the behavior of matplotlib.pyplot
[Python] A program to find the number of apples and oranges that can be harvested
Make a copy of the list in Python
A python amateur tries to summarize the list ②
[Python] A program that calculates the number of chocolate segments that meet the conditions
I made a program to check the size of a file in Python
How to pass the execution result of a shell command in a list in Python
Template of python script to read the contents of the file
How to write a list / dictionary type of Python3
[Python] Solution to the problem that elements are linked when copying a list
[Python] A program that calculates the number of updates of the highest and lowest records
Python script to get a list of input examples for the AtCoder contest
Python Note: The mystery of assigning a variable to a variable
How to get a list of files in the same directory with python
How to identify the element with the smallest number of characters in a Python list?
[Python] A program that finds the shortest number of steps in a game that crosses clouds
A program that summarizes the transaction history csv data of SBI SECURITIES stocks [Python3]
How to check in Python if one of the elements of a list is in another list
How to find the first element that matches your criteria in a Python list
[Ubuntu] How to delete the entire contents of a directory
Try to get the function list of Python> os package
[Python] How to make a list of character strings character by character
How to shuffle a part of a Python list (at random.shuffle)
[Maya Python] Crush the contents of the script 3 ~ List unknown Plugins
Get the number of specific elements in a python list
How to get a list of built-in exceptions in python
[Python] A program that finds the most common bird types
[Python3] List of sites that I referred to when I started Python
Extract the value closest to a value from a Python list element
About the basics list of Python basics
Get the value of a specific key up to the specified index in the dictionary list in Python
Summary of points to keep in mind when writing a program that runs on Python 2.5
[Python] Programming to find the number of a in a character string that repeats a specified number of times.
How to pass the execution result of a shell command in a list in Python (non-blocking version)
The story that the version of python 3.7.7 was not adapted to Heroku
How to determine the existence of a selenium element in Python
Extract the index of the original set list that corresponds to the list of subsets.
Try to get a list of breaking news threads in Python.
[python, ruby] fetch the contents of a web page with selenium-webdriver
How to check the memory size of a variable in Python
Output the contents of ~ .xlsx in the folder to HTML with Python
How to check the memory size of a dictionary in Python
A function that measures the processing time of a method in python
[Ev3dev] Create a program that captures the LCD (screen) using python
[Python3] Define a decorator to measure the execution time of a function
Try to write a program that abuses the program and sends 100 emails
A script that returns 0, 1 attached to the first Python prime number
Create a function to get the contents of the database in Go
The story of making a module that skips mail with python
[Python] A simple function to find the center coordinates of a circle
Create a compatibility judgment program with the random module of python.
I made a program in Python that changes the 1-minute data of FX to an arbitrary time frame (1 hour frame, etc.)