How to update and change the current domain array list

Question:

For example i have a list of website name examples

exist = ['http://sushiblast.com', 'http://funnyvideos-funny.info', 'https://youtube.com','https://api.forms.app/user/infobyname/minecraft']

Here is the code example that i used

input_str = exist
   
# Printing original string  
print ("Original string: " + input_str) 
   
result_str = "" 
   
for i in range(5, len(input_str)): 
    if i != 1: 
        result_str = result_str + input_str[i] 
   
# Printing string after removal   
print ("String after removal of i'th character : " + result_str)

In this one i tried to erase the https from the name list but, it doesn’t work with an array list.

Is there a way where i could erase the http:// and https:// from the array list while also changing the url example from 'https://api.forms.app/user/infobyname/minecraft' to my.forms.apps/minecraft

Thank you!

Asked By: Derrell Hasan

||

Answers:

import re

input_str = ['http://sushiblast.com', 'http://funnyvideos-funny.info', 'https://youtube.com','https://api.forms.app/user/infobyname/minecraft']
   
result_str = []
   
for i in input_str: 
    url = re.compile(r"https?://")
    url = url.sub('', i)
    if '/' in url:
        url = url.split('/')[0] + '/' + url.split('/')[-1]
    result_str.append(url.replace('api', 'my'))
   
print (result_str)

Output:

['sushiblast.com', 'funnyvideos-funny.info', 'youtube.com', 'my.forms.app/minecraft']
Answered By: Aymen
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.