assignment-02 - Python Strings
assignment-02 - Python Strings
Hello Innominion,
Join Mentoring Session for the Support/Doubts Resolving with Our Technical
Mentors (2.00 PM - 6.00 PM Mon-Sat)
In [ ]:
Strings - Execrise
In [40]: text = """The University of Hawaii began using radio to send digital information as earl
Friedhelm Hillebrand conceptualised SMS in 1984 while working for Deutsche Telekom. Sitt
Hillebrand typed out random sentences and counted every letter, number, punctuation, and
Almost every time, the messages contained fewer than 160 characters, thus giving the bas
limit one could type via text messaging. With Bernard Ghillebaert of France Télécom, he
a proposal for the GSM (Groupe Spécial Mobile) meeting in February 1985 in Oslo.
The first technical solution evolved in a GSM subgroup under the leadership of Finn Tros
It was further developed under the leadership of Kevin Holley and Ian Harris (see Short
SMS forms an integral part of SS7 (Signalling System No. 7). Under SS7, it is a "state" w
coded in the ITU-T "T.56" text format, that has a "sequence lead in" to determine differ
and may have special character codes that permits, for example, sending simple graphs as
This was part of ISDN (Integrated Services Digital Network) and since GSM is based on th
made its way to the mobile phone. Messages could be sent and received on ISDN phones,
and these can send SMS to any GSM phone. The possibility of doing something is one thing
implementing it another, but systems existed from 1988 that sent SMS messages to mobile
In [3]: len(text)
1507
Out[3]:
In [4]: len(text.split())
244
Out[4]:
In [3]: a=text.split()
b=set(a)
len(b)
174
Out[3]:
In [6]: number_of_words=244
number_of_unique_words=174
lexical_diversity=(number_of_words)/(number_of_unique_words)
lexical_diversity
1.4022988505747127
Out[6]:
In [2]: text1=text
text1.lower().count("the")
14
Out[2]:
In [3]: text1=text
text1.lower().count("a")
92
Out[3]:
Question: Append " Innomatics Reseach Labs" after first 10 words in the text
In [6]: c=a[:10]
c.append(" Innomatics Reseach Labs")
" ".join(c)
'The University of Hawaii began using radio to send digital Innomatics Reseach Labs'
Out[6]:
In [15]: text[0:15]
'The University of Hawaii began using radio to send digital information as early as'
Out[7]:
In [4]: a=text.upper()
b=a.split()
" ".join(b[0:10])
In [7]: a=text.lower()
b=a.split()
" ".join(b[0:10])
u
o hint - You need to use for loop for this
In [8]: a=text.lower()
b=a.split(" ")
abc = set()
for i in b:
if i.lower() and i.startswith('u'):
abc.add(i)
print("List of words starts with u is:")
print(abc)
In [9]: a=text.lower()
b=a.split(" ")
abc = set()
for i in b:
if i.lower() and i.startswith('o'):
abc.add(i)
print("List of words starts with o is:")
print(abc)
In [27]:
e
n hint - You need to use for loop for this
In [10]: a=text.lower()
b=a.split(" ")
abc = set()
for i in b:
if i.lower() and i.endswith('e'):
abc.add(i)
print("List of words ends with e is:")
print(abc)
In [11]: a=text.lower()
b=a.split(" ")
abc = set()
for i in b:
if i.lower() and i.endswith('n'):
abc.add(i)
print("List of words ends with n is:")
print(abc)
Question: Extract first 10 words of text and Capitalize first letter of each word
In [13]: a = text.replace("University","Innomatics")
a
'The Innomatics of Hawaii began using radio to send digital information as early as 197
Out[13]:
1,using ALOHAnet. \nFriedhelm Hillebrand conceptualised SMS in 1984 while working for De
utsche Telekom. Sitting at a typewriter at home, \nHillebrand typed out random sentences
and counted every letter, number, punctuation, and space. \nAlmost every time, the messa
ges contained fewer than 160 characters, thus giving the basis for the \nlimit one could
type via text messaging. With Bernard Ghillebaert of France Télécom, he developed \na pr
oposal for the GSM (Groupe Spécial Mobile) meeting in February 1985 in Oslo. \nThe first
technical solution evolved in a GSM subgroup under the leadership of Finn Trosby. \nIt w
as further developed under the leadership of Kevin Holley and Ian Harris (see Short Mess
age Service). \nSMS forms an integral part of SS7 (Signalling System No. 7). Under SS7,
it is a "state" with a 160 character data, \ncoded in the ITU-T "T.56" text format, that
has a "sequence lead in" to determine different language codes, \nand may have special c
haracter codes that permits, for example, sending simple graphs as text. \nThis was part
of ISDN (Integrated Services Digital Network) and since GSM is based on this, \nmade its
way to the mobile phone. Messages could be sent and received on ISDN phones, \nand these
can send SMS to any GSM phone. The possibility of doing something is one thing, \nimplem
enting it another, but systems existed from 1988 that sent SMS messages to mobile phones
(compare ND-NOTIS).'
Question: Convert the "text" into sentances and store those into one variable called
"sentance"
['The University of Hawaii began using radio to send digital information as early as 197
Out[14]:
1,using ALOHAnet',
' \nFriedhelm Hillebrand conceptualised SMS in 1984 while working for Deutsche Teleko
m',
' Sitting at a typewriter at home, \nHillebrand typed out random sentences and counted
every letter, number, punctuation, and space',
' \nAlmost every time, the messages contained fewer than 160 characters, thus giving th
e basis for the \nlimit one could type via text messaging',
' With Bernard Ghillebaert of France Télécom, he developed \na proposal for the GSM (Gr
oupe Spécial Mobile) meeting in February 1985 in Oslo',
' \nThe first technical solution evolved in a GSM subgroup under the leadership of Finn
Trosby',
' \nIt was further developed under the leadership of Kevin Holley and Ian Harris (see S
hort Message Service)',
' \nSMS forms an integral part of SS7 (Signalling System No',
' 7)',
' Under SS7, it is a "state" with a 160 character data, \ncoded in the ITU-T "T',
'56" text format, that has a "sequence lead in" to determine different language codes,
\nand may have special character codes that permits, for example, sending simple graphs
as text',
' \nThis was part of ISDN (Integrated Services Digital Network) and since GSM is based
on this, \nmade its way to the mobile phone',
' Messages could be sent and received on ISDN phones, \nand these can send SMS to any G
SM phone',
' The possibility of doing something is one thing, \nimplementing it another, but syste
ms existed from 1988 that sent SMS messages to mobile phones (compare ND-NOTIS)',
'']
Question:
'The University of Hawaii began using radio to send digital information as early as 197
Out[41]:
1,using ALOHAnet. Friedhelm Hillebrand conceptualised SMS in 1984 while working for Deu
tsche Telekom. Sitting at a typewriter at home, Hillebrand typed out random sentences a
nd counted every letter, number, punctuation, and space. Almost every time, the message
s contained fewer than 160 characters, thus giving the basis for the limit one could ty
pe via text messaging. With Bernard Ghillebaert of France Télécom, he developed a propo
sal for the GSM (Groupe Spécial Mobile) meeting in February 1985 in Oslo. The first tec
hnical solution evolved in a GSM subgroup under the leadership of Finn Trosby. It was f
urther developed under the leadership of Kevin Holley and Ian Harris (see Short Message
Service). SMS forms an integral part of SS7 (Signalling System No. 7). Under SS7, it is
a "state" with a 160 character data, coded in the ITU-T "T.56" text format, that has a
"sequence lead in" to determine different language codes, and may have special characte
r codes that permits, for example, sending simple graphs as text. This was part of ISDN
(Integrated Services Digital Network) and since GSM is based on this, made its way to t
he mobile phone. Messages could be sent and received on ISDN phones, and these can send
SMS to any GSM phone. The possibility of doing something is one thing, implementing it
another, but systems existed from 1988 that sent SMS messages to mobile phones (compare
ND-NOTIS).'
1. From the above sentace print the first word from each sentance
In [42]: b = text.split(".")
for i in b[:len(b)-1]:
res = i.split()
print(res[0])
The
Friedhelm
Sitting
Almost
With
The
It
SMS
7)
Under
56"
This
Messages
The
In [35]: b = text.split(".")
for i in b[:len(b):2]:
res = i
print(res)
The University of Hawaii began using radio to send digital information as early as 1971,
using ALOHAnet
Sitting at a typewriter at home,
Hillebrand typed out random sentences and counted every letter, number, punctuation, and
space
With Bernard Ghillebaert of France Télécom, he developed
a proposal for the GSM (Groupe Spécial Mobile) meeting in February 1985 in Oslo
It was further developed under the leadership of Kevin Holley and Ian Harris (see Short
Message Service)
7)
56" text format, that has a "sequence lead in" to determine different language codes,
and may have special character codes that permits, for example, sending simple graphs as
text
Messages could be sent and received on ISDN phones,
and these can send SMS to any GSM phone
H1e2l3l4o5w6o7r8l9d
Helloworld
In [43]: a="H1e2l3l4o5w6o7r8l9d"
a[: :2]
'Helloworld'
Out[43]:
In [ ]: