# readFile2List 1 line
f = open('c:/test.txt', 'r', encoding="utf-8"); l = f.read().splitlines(); f.close()
# writeString 1 liner
f = open('c:/', 'w', encoding='utf-8'); f.write('This is a test\n'); f.close()
# slice notation
# +---+---+---+---+---+
# | H | e | l | p | A |
# +---+---+---+---+---+
# 0 1 2 3 4 5
# -5 -4 -3 -2 -1
x = 'HelpA'; start = 0; end = 5; step = 1
x[start:end] # items start through end-1
x[start:] # items start through the rest of the list
x[:end] # items from the beginning through end-1
x[:] # a copy of the whole list
x[start:end:step] # start through not past end, by step
x[-1] # last item in the list
x[-2:] # last two items in the list
x[:-2] # everything except the last two items
# reverse of x
x = [1,2,3,4,5,6]
print(x[::-1]) # reverse of x
# [6,5,4,3,2,1]
# slice assignment
r=[1,2,3,4]
print(r[1:1])
# []
r[1:1]=[9,8]
print(r)
# [1, 9, 8, 2, 3, 4]
r[1:1]=['blah']
print(r)
# [1, 'blah', 9, 8, 2, 3, 4]
# list concatenation
a = [1,2,3,4,5]
b = [6,7,8,9,0]
print(a + b)
# [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
print(a + b[:3])
# [1, 2, 3, 4, 5, 6, 7, 8]
# c is a shallow copy of a
a = [1, 2, 3, 4]
b = a
c = a[:]
b[2] = 10
c[3] = 20
print(a)
# [1, 2, 10, 4]
print(b)
# [1, 2, 10, 4]
print(c)
# [1, 2, 3, 20]