Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Character Increment
#1
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.
Reply
#2
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']
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [solved] unexpected character after line continuation character paul18fr 4 571 Jun-22-2021, 03:22 PM
Last Post: deanhystad
  Increment text files output and limit contains Kaminsky 1 853 Jan-30-2021, 06:58 PM
Last Post: bowlofred
  Increment formula Kristenl2784 4 866 Jul-20-2020, 10:14 PM
Last Post: Kristenl2784
  [openpyxl] Increment cells being pasted into Template Kristenl2784 4 1,298 Jul-16-2020, 10:00 PM
Last Post: Kristenl2784
  SyntaxError: unexpected character after line continuation character siteshkumar 2 1,118 Jul-13-2020, 07:05 PM
Last Post: snippsat
  how can i handle "expected a character " type error , when I input no character vivekagrey 2 1,165 Jan-05-2020, 11:50 AM
Last Post: vivekagrey
  How can I increment a List item with in a "for in" msteffes 4 1,820 Aug-14-2019, 08:55 AM
Last Post: DeaD_EyE
  How define iteration interval increment SriMekala 5 1,856 Jun-01-2019, 01:06 PM
Last Post: ichabod801
  Replace changing string including uppercase character with lowercase character silfer 11 2,948 Mar-25-2019, 12:54 PM
Last Post: silfer
  SQlite3 quickly increment INT value? jmair 1 1,155 Mar-04-2019, 08:03 PM
Last Post: stranac

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020