What you need
- Basics of python
- knowledge on Dictionary and functions
- knowledge on Classes and objects.
OK!! HERE IS THE CODE 😊
import
random
import
string
def
create_shortURL(link):
chars
=
string.ascii_lowercase
# chars = ['a','c','z']
short_url
=
''.join(random.choice(chars)
for
i
in
range
(
5
))
d
=
{}
URL
=
'https://www.plc.ly/'
+
short_url
# PLC = Python Learn Camp
d[URL]
=
link
# This is optional
if
URL
in
d:
print
(
'Your URL:'
,d[URL])
print
(
'Shorten URL:'
,URL)
else
:
print
(
'No Short URL'
)
Here i used 2 simple and most used modules in python called strings and random.
I used dictionary to store short url and original url. we stored the short url as keys and original url as valeus in python dictionary.
https://www.plc.ly/: This is our domain URL. This is an example URL. we never purchase this, but if you want to implement this project and deploy on the server, then you need to purchase this your custom URL.
short_url: here we are generating 5 random lowercase characters and we append them to our domain URL, so that becomes our shortner URL.
FOLLOW OUR INSTAGRAM PAGE & ALSO SHARE TO YOUR FRIENDS 😊