Python Forum

Full Version: Character Increment
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, can anyone help me to writing me this code:
if first index of id is Sweety1 then it continue till ‘Z’ like Sweety1_a, Sweety1_b till Sweety1_z, And after its counter will increment to 2 and the value will be Sweety2_a,Sweety2_b till Sweet2_z and if more entries of names then it continue to Sweety3,Sweety3_a,Sweety4,Sweety4_a…Sweety4_Z.
Please Help.
from itertools import product 
from string import ascii_lowercase
base = 'Sweety'
print([f'{base}_{idx}_{char}' for idx, char in product(range(1, 5), ascii_lowercase)])
Output:
['Sweety_1_a', 'Sweety_1_b', 'Sweety_1_c', 'Sweety_1_d', 'Sweety_1_e', 'Sweety_1_f', 'Sweety_1_g', 'Sweety_1_h', 'Sweety_1_i', 'Sweety_1_j', 'Sweety_1_k', 'Sweety_1_l', 'Sweety_1_m', 'Sweety_1_n', 'Sweety_1_o', 'Sweety_1_p', 'Sweety_1_q', 'Sweety_1_r', 'Sweety_1_s', 'Sweety_1_t', 'Sweety_1_u', 'Sweety_1_v', 'Sweety_1_w', 'Sweety_1_x', 'Sweety_1_y', 'Sweety_1_z', 'Sweety_2_a', 'Sweety_2_b', 'Sweety_2_c', 'Sweety_2_d', 'Sweety_2_e', 'Sweety_2_f', 'Sweety_2_g', 'Sweety_2_h', 'Sweety_2_i', 'Sweety_2_j', 'Sweety_2_k', 'Sweety_2_l', 'Sweety_2_m', 'Sweety_2_n', 'Sweety_2_o', 'Sweety_2_p', 'Sweety_2_q', 'Sweety_2_r', 'Sweety_2_s', 'Sweety_2_t', 'Sweety_2_u', 'Sweety_2_v', 'Sweety_2_w', 'Sweety_2_x', 'Sweety_2_y', 'Sweety_2_z', 'Sweety_3_a', 'Sweety_3_b', 'Sweety_3_c', 'Sweety_3_d', 'Sweety_3_e', 'Sweety_3_f', 'Sweety_3_g', 'Sweety_3_h', 'Sweety_3_i', 'Sweety_3_j', 'Sweety_3_k', 'Sweety_3_l', 'Sweety_3_m', 'Sweety_3_n', 'Sweety_3_o', 'Sweety_3_p', 'Sweety_3_q', 'Sweety_3_r', 'Sweety_3_s', 'Sweety_3_t', 'Sweety_3_u', 'Sweety_3_v', 'Sweety_3_w', 'Sweety_3_x', 'Sweety_3_y', 'Sweety_3_z', 'Sweety_4_a', 'Sweety_4_b', 'Sweety_4_c', 'Sweety_4_d', 'Sweety_4_e', 'Sweety_4_f', 'Sweety_4_g', 'Sweety_4_h', 'Sweety_4_i', 'Sweety_4_j', 'Sweety_4_k', 'Sweety_4_l', 'Sweety_4_m', 'Sweety_4_n', 'Sweety_4_o', 'Sweety_4_p', 'Sweety_4_q', 'Sweety_4_r', 'Sweety_4_s', 'Sweety_4_t', 'Sweety_4_u', 'Sweety_4_v', 'Sweety_4_w', 'Sweety_4_x', 'Sweety_4_y', 'Sweety_4_z']