Skip to content

Commit 2454a64

Browse files
authored
Strinngs
1 parent 5cf34f7 commit 2454a64

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

String 2.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python
2+
# coding: utf-8
3+
4+
# # Return the number of times that the string "hi" appears anywhere in the given string.
5+
#
6+
#
7+
8+
# In[1]:
9+
10+
11+
def count_hi(str):
12+
return str.count("hi")
13+
count_hi('hihihihi')
14+
15+
16+
# # Given a string, return a string where for every char in the original, there are two chars.
17+
#
18+
#
19+
20+
# In[2]:
21+
22+
23+
def double_char(str):
24+
new_str = ""
25+
for char in str:
26+
new_str += char*2
27+
return new_str
28+
double_char('Hi-There')
29+
30+
31+
# # Return True if the string "cat" and "dog" appear the same number of times in the given string.
32+
33+
# In[4]:
34+
35+
36+
def cat_dog(str):
37+
return str.count('cat') == str.count('dog')
38+
39+
cat_dog('1cat1cadodog')
40+
41+
42+
# In[ ]:
43+
44+
45+
46+

0 commit comments

Comments
 (0)