I have write python code and it has too many for loop, as a result, my code readability is too low and pylint star too low.
I am finding a way to solve same with fewer line of code.
here you go for my snippet:
numberlist = [1,3,5]
stringlist = ['a', 'b', 'c']
id = '458'
numbered_string = []
for n, s in numberlist, stringlist:
num_str = "{}{}".format(
n,
s,
id,
)
numbered_string.append(num_str)
codes = []
for n,s, sn in numberlist, stringlist, numbered_string:
code = make_code(
n,
s,
sn
)
codes.append(code)
print(codes)
Ignore the function make_code() , or let's assume the make_code() is
def make_code(n,s, sn):
return str(n) + str(s) + str(sn)
Can anyone help me shorten the snippet?, please ignore the function. I want to improve this code much better and high readability, too many instance is not a solution.
numbered_stringto contain? Because as is, your code gives an error atfor n, s in numberlist, stringlist:(should be zipped?)