Skip to content

Commit d109352

Browse files
authored
Find function
1 parent 762542a commit d109352

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

6. Finding Characters

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Assignment: Find Characters
2+
# Write a program that takes a list of strings and a string containing a single character, and prints a new list of all the strings containing that character.
3+
4+
# Here's an example:
5+
6+
# # input
7+
# word_list = ['hello','world','my','name','is','Anna']
8+
# char = 'o'
9+
# # output
10+
# new_list = ['hello','world']
11+
# # Hint: how many loops will you need to complete this task?
12+
13+
def find_character(word_list, char):
14+
new_list = []
15+
for i in range(0, len(word_list)):
16+
17+
if word_list[i].find(char) != -1:
18+
new_list.append(word_list[i])
19+
20+
print new_list
21+
22+
test_list = ['hello','world','my','name','is','Anna']
23+
find_character(test_list, 'o')

0 commit comments

Comments
 (0)