Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to update and change the current domain array list

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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!

>Solution :

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']
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading