-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandlingText.py
More file actions
53 lines (41 loc) · 1.67 KB
/
HandlingText.py
File metadata and controls
53 lines (41 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# a python program for handling text
text1 = "The young boys of Malindi have given us a warm welcome. Look out for what they did in the next post 🌊"
i = print('text length is : ', len(text1))
print ('------------------------------------------------------------------------------------------------------')
k = text1.split(' ')
j = len(k)
print(k)
print(j)
print ('------------------------------------------------------------------------------------------------------')
'''
text1 = "The young boys of Malindi have given us a warm welcome. Look out for what they did in the next post 🌊"
# Get the length of the text
text_length = len(text1)
print('Text length is:', text_length)
# Split the text into words and print them
words = text1.split(' ')
print('Split:', words)
'''
print ('Words with len()>= 4')
words_split = text1.split(' ')
words = [w for w in words_split if len(w) >= 4]
print(words)
'''
text1 = "The young boys of Malindi have given us a warm welcome. Look out for what they did in the next post 🌊"
# Split the text into words
words = text1.split()
# Filter the words with length >= 4
filtered_words = [w for w in words if len(w) >= 4]
# Print the filtered words
print('Words with len() >= 4:', filtered_words)
'''
print ('------------------------------------------------------------------------------------------------------')
print ('Capital words')
words_split = text1.split(' ')
words = [w for w in words_split if w.istitle()]
print(words)
print ('------------------------------------------------------------------------------------------------------')
print ('Words end with e')
words_split = text1.split(' ')
words = [w for w in words_split if w.endswith('e')]
print(words)