Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I would like to convert the string to an integers as shown below, separated by "." with a=1,b=2,...z=26

text = 'Hello World"

Expected output:

     H.E.L .L. O  W. O. R. L. D

---> 8.5.12.12.15 23.15.18.12.4

#split the words

text ="Hello world"

text = text.upper()

splitted_text = text.split(" ")

#map characters to integers

import string

for x, y in zip(range(1, 27), string.ascii_lowercase):

    print(x, y)

I don't know how do I proceed from here.

1 Answer

0 votes
by (36.8k points)

Use the below code:

text = "Hello World".lower()

li = []

for i in text:

    if i!=' ':

        li.append(str(ord(i)-96))

    

print('.'.join(li))

 If you want to know more about the Data Science then do check out the following Data Science which will help you in understanding Data Science from scratch

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...