How to edit the line appended into list multiple times?

Multi tool use


How to edit the line appended into list multiple times?
Have a scenario where,
a. Previously the list was having one value only, so it was a straight away adding the line like given below.
s_array.append(' %s [%d:0] %s;'%(str(s_ud_in_cfg_array[i][1]), int(s_ud_l_var_temp[0]), str(s_ud_in_cfg_array[i][0]), ))
b. Have a scenario where a list has multiple values like
s_ud_l_var_tmp = ['32', '64', '16']
c. I wanted to add a line with the values from the array as given below into a list.
s_array.append(' %s [%d:0][%d:0][%d:0] %s;'%(str(s_ud_in_cfg_array[i][1]), int(s_ud_l_var_temp[0]), int(s_ud_l_var_temp[1]), int(s_ud_l_var_temp[2]), str(s_ud_in_cfg_array[i][0]), ))
c. But the catch here is the value in the s_ud_l_var_tmp can be keep varying and it won't be three all the times.
So in that case how to add [%d:0] and the corresponding values on the right side?
Please share your comments and inputs.
[%d:0]
@GalAbra: That's what I am trying it out. I tried adding the [%d:0] series into an array. But then I am confused on how to add the elements on the right side.
– Desperado
20 mins ago
1 Answer
1
Is this what you were trying to achieve?
s_ud_in_cfg_array = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']]
s_ud_l_var_temp = [1, 2, 3]
s_array = ;
for i in range(0, len(s_ud_in_cfg_array)):
s_array.append(' %s [%d:0] %s;' % (str(s_ud_in_cfg_array[i][1]), int(s_ud_l_var_temp[0]), str(s_ud_in_cfg_array[i][0])))
print(s_array)
// output: [' b [1:0] a;', ' e [1:0] d;', ' h [1:0] g;']
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
If you generate the
[%d:0]
chain seperately your code will be much more dynamic, modular and readable.– GalAbra
46 mins ago