0
(YOUTUBE LINK FINDER PROGRAM) How to increment to the next value of character in I
Here I am aware of the fact that I represents the character that's held in yt_link variable so when I run the if statement until the I value turns to "." then I want to go to the next character that's supposed to be beside "."Which might be "b" if its true then go to next character which could be "e" if true then next so if all the conditions are true then I want split the link by split(".be") and get the youtube ID and print it out How exactly would i be able to do that guys https://code.sololearn.com/cXnKI5C2xGm8/?ref=app
7 Réponses
+ 3
Look at this and you'll get the idea ...
yt_links = ( "https://www.youtube.com/watch?v=kbxkq_w51PM", "https://youtu.be/KMBBjzp5hdc" )
for link in yt_links:
if "watch?v=" in link: # link contains 'watch?v='
# add 8 to the slicing index (length of 'watch?v=')
pure_link = link[ link.index( "watch?v=" ) + 8 : ]
elif "youtu.be/" in link: # link contains 'youtu.be'
# add 9 to slicing index (length of 'youtu.be/')
pure_link = link[ link.index( "youtu.be/" ) + 9 : ]
print( pure_link )
# Reference:
# https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/ref_string_index.asp
+ 4
u = input()
try:
print(u.split("=")[1])
except:
print(u.split("/")[-1])
# Keep learning & happy coding :D
https://www.sololearn.com/Codes?ordering=MostRecent&query=YouTube%20Link%20Finder
+ 1
Torg Just simple hint for you do solve it with less code: look at str.startswith() 😉
+ 1
Time To Code could you redirect me to some other programs or anything that gives a brief idea about regex, tried studying it seems confusing ngl
+ 1
Ilyas Bakirov thanks bro but have you got any programs or links that teaches it well