+ 1
YouTube Link Finder fail
I fail at test case 4. Tell me why? https://code.sololearn.com/cUKz995N834s/?ref=app
6 Réponses
+ 4
import re
takeLink =list(input())
stri="".join(takeLink )
backSlash=0
if re.search("com",stri):
for i in range(len(takeLink)):
if takeLink[i]==r'=':
break
print("".join(takeLink[i+1:]))
else:
for i in range(len(takeLink )):
if takeLink[i]==r'/':
backSlash +=1
if backSlash == 3:
break
print ("".join(takeLink[i+1:]))
+ 4
Try it.
+ 4
i think mine and your so many different?😕
+ 1
I think yours is true. But why my code fail? I don't find any case make my code fail.
+ 1
Maybe a shortest way ... :
link = input()
link= link.replace('https://','')
if 'youtu.be' in link:
link=link.replace('youtu.be/','')
elif 'youtube' in link:
link=link.replace('www.youtube.com/watch?v=','')
print(link)
+ 1
You and your friends like to share YouTube links all throughout the day. You want to keep track of all the videos you watch in your own personal notepad, but you find that keeping the entire link is unnecessary.
Keep the video ID (the combination of letters and numbers at the end of the link) in your notepad to slim down the URL.
Task:
Create a program that parses through a link, extracts and outputs the YouTube video ID.
Input Format:
A string containing the URL to a YouTube video. The format of the string can be in "https://www.youtube.com/watch?v=kbxkq_w51PM" or the shortened "https://youtu.be/KMBBjzp5hdc" format.
Output Format:
A string containing the extracted YouTube video id.
Sample Input:
https://www.youtube.com/watch?v=RRW2aUSw5vU
Sample Output:
RRW2aUSw5vU
import re
takeLink =list(input())
stri="".join(takeLink )
backSlash=0
if re.search("com",stri):
for i in range(len(takeLink)):
if takeLink[i]==r'=':
break
print("".join(takeLink[i+1:]))