>>> numbers = (1, 2, 3)
>>> fnames = ('file{}.txt'.format(i) for i in numbers)
>>> files = [open(i, 'w', encoding='utf-8') for i in fnames]
>>> files
[<_io.TextIOWrapper name='file1.txt' mode='w' encoding='utf-8'>, <_io.TextIOWrapper name='file2.txt' mode='w' encoding='utf-8'>, <_io.TextIOWrapper name='file3.txt' mode='w' encoding='utf-8'>]
>>> [i.close() for i in files]
[None, None, None]
>>>
[guest@localhost t]$ ls
file1.txt file2.txt file3.txt
[guest@localhost t]$
files = [open('freq{}.txt'.format(i), 'w') for i in range(N)]
f2 = open('file2.txt')
i = 0
for l in f2.radlines():
files[i].write(l)
i = (i+1) % N
f2.close()
for f in files:
f.close()
import math
def getAmplitudesArray(array):
amplitudesArray = []
multiplier = 2
for item in array:
amplitudesArray.append(float(item * math.sqrt(multiplier)))
multiplier *= 2
return amplitudesArray
array = [1] * 10
print(getAmplitudesArray(array))
>>> [1.4142135623730951,
2.0,
2.8284271247461903,
4.0, 5.656854249492381,
8.0, 11.313708498984761,
16.0,
22.627416997969522,
32.0]
import matplotlib.pyplot as plt
import numpy as np
t = np.linspace(0, np.pi, 314)
y = np.sin(t)
plt.figure(1)
plt.plot(t, y, '-g')
plt.plot(t[100:150:5], y[100:150:5], 'og')
plt.plot(t[::10], y[::10], '*r')
plt.show()