This is a memo for myself.
▼ Question
--Rotate the contents of list to the left by the specified integer.
▼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()
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