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
#1
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]))
        
Reply
#2
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.
Reply
#3
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
Reply
#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
#5
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
Reply
#6
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.
Reply
#7
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)
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
#8
(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
Reply
#9
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'
Reply
#10
(Sep-28-2020, 06:16 AM)bowlofred Wrote: I thought there were 22 positions.
according to their question, first 2 are always UC
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
  Need to fix SyntaxError in cycle try alexfrol86 14 3,230 Mar-27-2022, 07:53 AM
Last Post: stevendaprano
  add Escape charcters in string GrahamL 3 1,200 Jan-20-2022, 01:15 PM
Last Post: GrahamL
  <while> cycle is not interrupted when using the <random>module ShityCoder 3 2,176 Sep-04-2020, 04:05 PM
Last Post: ShityCoder
  Cycle of numpy variables Zero01 0 1,565 Jul-31-2020, 11:58 AM
Last Post: Zero01
  stop cycle while windows11 1 2,023 May-16-2020, 03:17 PM
Last Post: deanhystad
  Occurrences using FOR and IF cycle P86 2 2,540 Jul-29-2019, 04:37 PM
Last Post: ThomasL
  pool map cycle skorost5 5 3,845 Apr-07-2019, 09:21 AM
Last Post: skorost5
  lifetime cycle counter Ixxxxxx 0 2,497 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