Может быть, это не общее решение, но основа проблемы, вы можете сделать творческое решение.Как и в следующем коде
# Put variable name in var
# These are empty lists that have already been defined
var = ["j", "u", "k", "b", "bi", "bit", "bitb", "bitc", "bitd", "bite"]
for i in range(len(ga)):
# Finding var index base of ga[i] value.
var_index = ga[i] // 3600
if ga[i] % 3600 == 0 and ga[i] > 0:
var_index -= 1
# Add the ga index to the corresponding list
eval(var[var_index] + ".append(" + str(i) + ")")
Но лучше использовать словарь, а не определять множество переменных.Как следующий код.
# Define dictionary
ch = {"j":[], "u":[], "k":[], "b":[], "bi":[],
"bit":[], "bitb":[], "bitc":[], "bitd":[], "bite":[]}
# Dictionary keys
key = ["j", "u", "k", "b", "bi", "bit", "bitb", "bitc", "bitd", "bite"]
for i in range(len(ga)):
# Finding key index base of ga[i] value.
key_index = ga[i] // 3600
if ga[i] % 3600 == 0 and ga[i] > 0:
key_index -= 1
# Add the ga index to the corresponding list in the dictionary
ch[key[key_index]].append(i)