dictionary :- split and count length
##sentence:-input, key:-word, value:-length of word
sentence=input("enter the sentence")
z=sentence.split(" ")
print(z)
##split :-provides us words in list
a={z:len(z) for z in z}
print(a)
"C:\Users\darul Haram\PycharmProjects\pythonProject2\venv\Scripts\python.exe" "C:/Users/darul Haram/PycharmProjects/pythonProject2/venv/Lib/dictionary comprehension 2.py" enter the sentenceall human is being is created to worship one god ['all', 'human', 'is', 'being', 'is', 'created', 'to', 'worship', 'one', 'god', ''] {'all': 3, 'human': 5, 'is': 2, 'being': 5, 'created': 7, 'to': 2, 'worship': 7, 'one': 3, 'god': 3, '': 0} Process finished with exit code 0
Comments
Post a Comment