I think I always have this problem that, whenever I want to save each output from the for loop
I always implement it by giving an individual valuable for each of them.
But the question is that, sometimes the iteration of for loop
is large, or sometimes the number of the valuables depends on the user input, It is a bad way to name every variable.
In my case:
for i in enumerate(actual_noises):
if i[0] == 0:
n1_wave, n1_sr = AudioUtil.load(i[1])
n1_wave, n1_sr = AudioUtil.rechannel((n1_wave, n1_sr), self.channels)
n1_wave, n1_sr = AudioUtil.resample((n1_wave, n1_sr), self.sr)
if i[0] == 1:
n2_wave, n2_sr = AudioUtil.load(i[1])
n2_wave, n2_sr = AudioUtil.rechannel((n2_wave, n2_sr), self.channels)
n2_wave, n2_sr = AudioUtil.resample((n2_wave, n2_sr), self.sr)
if i[0] == 2:
n3_wave, n3_sr = AudioUtil.load(i[1])
n3_wave, n3_sr = AudioUtil.rechannel((n3_wave, n3_sr), self.channels)
n3_wave, n3_sr = AudioUtil.resample((n3_wave, n3_sr), self.sr)
noisy_data = clean_wave + noise_1 + noise_2 + noise_3
The actual_noise
is a list of k
wav files:
noise type: ['/path_to/noise_1.wav', '/path_to/noise_2.wav', '/path_to/noise_3.wav']
In this case k = 3
, however, I actually set it as a parameter which does not have to be fixed.
So I would like to know if there are better ways to deal with the output from the for loop
.
Thanks a lot in advance! :)