-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString
More file actions
126 lines (89 loc) · 2.26 KB
/
String
File metadata and controls
126 lines (89 loc) · 2.26 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
---------palindrome---------
def pal_str(string):
return string == string[::-1]
print(pal_str("oyo"))
#----------vowels count-----
def c_v(word):
count =0
vowels="aeiouAEIOU"
new = len([char for char in word if char in vowels])
#for char in word:
if char in vowels:
count+=1
return count
return new
word="Anonymous"
print(c_v(word))
#------concat lis----------
def word(words):
#return " ".join(words)
s=' '
for i in words:
s+=i+" "
return s.strip( )
words=["i",'love',"myself"]
print(word(words))
# ------rev string-----
def rev_str(words):
return words[::-1]
words="baba"
print(rev_str(words))
#-------count words-----
def rev_str(words):
return len(words)
#count=0
for i in range(0,len(words)-1):
if (words[i] == ' 'and words[i+1].isalpha and (i>0)):
count+=1
return count
words="Codes ban rhe hai"
print(rev_str(words))
#---------remove vowels----------
def rem_vow(words):
new=" "
vowels="aeiouAEIOU"
for i in words:
if i not in vowels:
new+=i
return new
words="fear out"
print(rem_vow(words))
#-----len of longest word in string-----
def long_word(sentence):
s=sentence.split()
k= sorted(s,key=len)
return (k[-1])
sentence="muze lgta thaa coding se dar "
print(long_word(sentence))
#---------sentence in reverse----------
def rev_ord(sentence):
new = sentence.split(" " )
return " ".join(reversed(new))
#return new
sentence="baghal me chora gaon me dhindora!"
print(rev_ord(sentence))
#-----------start with vowels----------
def starts_vow(names):
count=0
vowels='aeiouAEIOU'
for i in names:
if i[0] in vowels:
count+=1
return count
names=["apple","Horse","Null","Oranges"]
starts_vow(names)
#------remove duplicates----
def dup_char(name):
new=" "
for i in name:
if i not in new:
new+=i
#new=name.split(' ')
return str(new)
name="ayan"
print(dup_char(name))
#------word is in sentence or not------
def word_avai(sentence,word):
return (word in sentence)
sentence,word=["I am pro coder now","gamer"]
print(word_avai(sentence,word))