YouTube Link Finder fail | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

YouTube Link Finder fail

I fail at test case 4. Tell me why? https://code.sololearn.com/cUKz995N834s/?ref=app

18th Apr 2020, 10:54 AM
Hiếu Võ Trần Minh
Hiếu Võ Trần Minh - avatar
6 Answers
+ 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:]))
19th Apr 2020, 7:32 AM
Manshu
Manshu - avatar
+ 4
Try it.
19th Apr 2020, 7:35 AM
Manshu
Manshu - avatar
+ 4
i think mine and your so many different?😕
19th Apr 2020, 8:48 AM
Manshu
Manshu - avatar
+ 1
I think yours is true. But why my code fail? I don't find any case make my code fail.
19th Apr 2020, 8:10 AM
Hiếu Võ Trần Minh
Hiếu Võ Trần Minh - avatar
+ 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)
26th Aug 2020, 8:53 PM
Evan Cocain
Evan Cocain - avatar
+ 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:]))
12th Nov 2020, 1:16 AM
MD FAYSAL MAHMUD
MD FAYSAL MAHMUD - avatar