Python Forum
Trying to cycle through a list of charcters - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Trying to cycle through a list of charcters (/thread-29965.html)

Pages: 1 2


Trying to cycle through a list of charcters - pooky2483 - Sep-27-2020

I'm trying to cycle through a length of characters but I am having problems figuring out how to just have 22 show. instead I am getting the following result; I can't figure out how to make the last column cycle through 'source' first and then move onto the next column and to the same, 22 times upto the last character.
Output:
be.com/channel/UC6https://www.youtube.com/channel/UC7https://www.youtube.com/channel/UC8https://www.youtube.com/channel/UC9 --https://www.youtube.com/channel/UC__https://www.youtube.com/channel/UCaahttps://www.youtube.com/channel/UCbbhttps://www.youtube.com/channel/UCcchttps://www.youtube.com/channel/UCddhttps://www.youtube.com/channel/UCeehttps://www.youtube.com/channel/UCffhttps://www.youtube.com/channel/UCgghttps://www.youtube.com/channel/UChhhttps://www.youtube.com/channel/UCiihttps://www.youtube.com/channel/UCjjhttps://www.youtube.com/channel/UCkkhttps://www.youtube.com/channel/UCllhttps://www.youtube.com/channel/UCmmhttps://www.youtube.com/channel/UCnnhttps://www.youtube.com/channel/UCoohttps://www.youtube.com/channel/UCpphttps://www.youtube.com/channel/UCqqhttps://www.youtube.com/channel/UCrrhttps://www.youtube.com/channel/UCsshttps://www.youtube.com/channel/UCtthttps://www.youtube.com/channel/UCuuhttps://www.youtube.com/channel/UCvvhttps://www.youtube.com/channel/UCwwhttps://www.youtube.com/channel/UCxxhttps://www.youtube.com/channel/UCyyhttps://www.youtube.com/channel/UCzzhttps://www.youtube.com/channel/UCAAhttps://www.youtube.com/channel/UCBBhttps://www.youtube.com/channel/UCCChttps://www.youtube.com/channel/UCDDhttps://www.youtube.com/channel/UCEEhttps://www.youtube.com/channel/UCFFhttps://www.youtube.com/channel/UCGGhttps://www.youtube.com/channel/UCHHhttps://www.youtube.com/channel/UCIIhttps://www.youtube.com/channel/UCJJhttps://www.youtube.com/channel/UCKKhttps://www.youtube.com/channel/UCLLhttps://www.youtube.com/channel/UCMMhttps://www.youtube.com/channel/UCNNhttps://www.youtube.com/channel/UCOOhttps://www.youtube.com/channel/UCPPhttps://www.youtube.com/channel/UCQQhttps://www.youtube.com/channel/UCRRhttps://www.youtube.com/channel/UCSShttps://www.youtube.com/channel/UCTThttps://www.youtube.com/channel/UCUUhttps://www.youtube.com/channel/UCVVhttps://www.youtube.com/channel/UCWWhttps://www.youtube.com/channel/UCXXhttps://www.youtube.com/channel/UCYYhttps://www.youtube.com/channel/UCZZhttps://www.youtube.com/channel/UC00https://www.youtube.com/channel/UC11https://www.youtube.com/channel/UC22https://www.youtube.com/channel/UC33https://www.youtube.com/channel/UC44https://www.youtube.com/channel/UC55https://www.youtube.com/channel/UC66https://www.youtube.com/channel/UC77https://www.youtube.com/channel/UC88https://www.youtube.com/channel/UC99
addr = "https://www.youtube.com/channel/UC"
source = "-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
for c in source:
    for a in range(21):
        print(addr.join([char * a for char in source]))
        



RE: Trying to cycle through a list of charcters - deanhystad - Sep-27-2020

sep.join(items) joins all the strings in "items" together using "sep" as a separator. When you do print(addr.join([char * a for char in source])) for a = 0, the comprehension returns 68 empty strings, the join command glues these together with 67 copies of addr, and you end up with "https://www.youtube.com/channel/UC" repeated 67 times.

I think you want to do this
addr = "https://www.youtube.com/channel/UC"
source = "-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
x = []
for c in source:
    for a in range(1, 21):
        x += addr.join([addr + char * a for char in source])
At least this generates a ton of strings all starting with addr.


RE: Trying to cycle through a list of charcters - pooky2483 - Sep-27-2020

So, how do i shorten it down to 22 characters, as in a YT address;
https://www.youtube.com/channel/UC8d_Dl60fLdoK8cP-4bXx6E
And then cycle through
----------------------
---------------------_
---------------------a
---------------------b

etc...

-------------------dun
-------------------duo
-------------------dup


RE: Trying to cycle through a list of charcters - bowlofred - Sep-27-2020

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



RE: Trying to cycle through a list of charcters - pooky2483 - Sep-28-2020

They need to be always 22 characters long, however, there is another YT address that uses about half the amount;
https://www.youtube.com/watch?v=8dXDl60fLdo
I'll probably attack that one later.

The one I'm concentrating on at first is addresses like https://www.youtube.com/channel/UCWRuNfWsKUiiCG1zmqPve7Q
That's one standard of a YT web address.

Looking at your program, which seems like the way I was going to go, but I was not sure how to do it, if you look at my comments...

# Characters used in address
# - 45
# _ 95
# 0123456789 48 - 57
# abcdefghijklmnopqrstuvwxyz 97 - 122
# ABCDEFGHIJKLMNOPQRSTUVWXYZ 65 - 90
#
# import string
# from string import ascii_lowercase
# from string import ascii_uppercase
# from string import digits
#
# lc = string.ascii_lowercase
# uc = string.ascii_uppercase
# dig = string.digits
#

import webbrowser

addr = "https://www.youtube.com/channel/UC"
source = "-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
for c in source:
    for a in range(21):
        print(addr.join([char * a for char in source]))

   # webbrowser.open addr.join([char * a for char in source])
# Needs a third loop somehow



RE: Trying to cycle through a list of charcters - bowlofred - Sep-28-2020

I don't know what your question is.

Are you trying to generate 22 character IDs (randomly? sequentially?) Are you trying to decode youtube addresses? If you want to generate them sequentially, just change the repeat=3 in the code above to repeat=22. (At 5 x 10^39 different codes, it's going to take some time to work through them)

Youtube doesn't create IDs by just incrementing. That way folks can't predict what future codes will be, and the generation can be distributed among multiple servers.


RE: Trying to cycle through a list of charcters - buran - Sep-28-2020

So basically you are trying to bruteforce all possible permutations with repetitions of 20 chars out of 64 (also called partial permutations, variations, arrangements)? these are 64**20 words (1329227995784915872903807060280344576)


RE: Trying to cycle through a list of charcters - pooky2483 - Sep-28-2020

(Sep-28-2020, 05:45 AM)bowlofred Wrote: I don't know what your question is.

Are you trying to generate 22 character IDs (randomly? sequentially?) Are you trying to decode youtube addresses? If you want to generate them sequentially, just change the repeat=3 in the code above to repeat=22. (At 5 x 10^39 different codes, it's going to take some time to work through them)

Youtube doesn't create IDs by just incrementing. That way folks can't predict what future codes will be, and the generation can be distributed among multiple servers.

Yes, I'm trying to do it sequentially.
How do you get 5 x 10^39 = 5e+39 when Buran works it out to 64**20 (Isn't that 64^20)= 1.329228e+36 ?
Could you explain how it's worked out?
There should also be numbers in it too...
0 - 9 (10)
a - z (26)
A - Z (26)
- - _ (2)
Total 64


RE: Trying to cycle through a list of charcters - bowlofred - Sep-28-2020

I thought there were 22 positions. If there's only 20, then yes the other figure is correct.

>>> f"{64**20:e}"
'1.329228e+36'
>>> f"{64**22:e}"
'5.444518e+39'



RE: Trying to cycle through a list of charcters - buran - Sep-28-2020

(Sep-28-2020, 06:16 AM)bowlofred Wrote: I thought there were 22 positions.
according to their question, first 2 are always UC