Python Forum
Trying to cycle through a list of charcters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to cycle through a list of charcters
#4
Keep track of the incremental part separately and then tack it on to the end. Do you want to always have exactly the same number of characters in the unique part, or do you want to add new characters if you run out?

import string
from itertools import product

def unique_sequence_generator():
    letterspace = (string.ascii_lowercase +
                   string.ascii_uppercase +
                   string.digits +
                   "-_")
    for seq in product(letterspace, repeat=3):
        yield "".join(seq)

i = unique_sequence_generator()
for _ in range(5):
    print(next(i))
This creates an iterator that will return all the 3-character sequences of the letterspace. Just call next() on it or put it in a for loop to pull elements from it.

Output:
aaa aab aac aad aae
Reply


Messages In This Thread
RE: Trying to cycle through a list of charcters - by bowlofred - Sep-27-2020, 08:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need to fix SyntaxError in cycle try alexfrol86 14 3,253 Mar-27-2022, 07:53 AM
Last Post: stevendaprano
  add Escape charcters in string GrahamL 3 1,210 Jan-20-2022, 01:15 PM
Last Post: GrahamL
  <while> cycle is not interrupted when using the <random>module ShityCoder 3 2,207 Sep-04-2020, 04:05 PM
Last Post: ShityCoder
  Cycle of numpy variables Zero01 0 1,569 Jul-31-2020, 11:58 AM
Last Post: Zero01
  stop cycle while windows11 1 2,052 May-16-2020, 03:17 PM
Last Post: deanhystad
  Occurrences using FOR and IF cycle P86 2 2,548 Jul-29-2019, 04:37 PM
Last Post: ThomasL
  pool map cycle skorost5 5 3,861 Apr-07-2019, 09:21 AM
Last Post: skorost5
  lifetime cycle counter Ixxxxxx 0 2,509 Mar-07-2018, 07:26 PM
Last Post: Ixxxxxx

Forum Jump:

User Panel Messages

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