Skip to content

Commit cecdd26

Browse files
solution to strings and lists assignment
1 parent 2c23582 commit cecdd26

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

strings_and_lists.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
words = "It's thanksgiving day. It's my birthday,too!"
2+
3+
index = words.find("day")
4+
print index
5+
new_str = words.replace("day", "month")
6+
print new_str
7+
8+
x = [2,54,-2,7,12,98]
9+
def newList(list):
10+
print min(list)
11+
print max(list)
12+
newList(x);
13+
14+
def firstAndLast(list):
15+
newList = []
16+
newList.append(list[0])
17+
newList.append(list[-1])
18+
print newList
19+
firstAndLast(x);
20+
21+
y = [19,2,54,-2,7,12,98,32,10,-3,6]
22+
y.sort()
23+
first = y[:5]
24+
second = y[4:]
25+
print second
26+
print first
27+
second.insert(0, first)
28+
print second
29+
30+
31+
#sorts in place; if not sorting in place would save to a var
32+
y.sort()
33+
first = y[:len(y)/2]
34+
second = y[len(y)/2:]
35+
print first
36+
print second
37+
second.insert(0, first)
38+
print second
39+
40+
#insert does not work when saving to a var -- not sure why
41+
y = [19,2,54,-2,7,12,98,32,10,-3,6]
42+
y.sort()
43+
first = y[:5]
44+
second = y[5:]
45+
print second
46+
newNested =second.insert(0, first)
47+
print newNested

0 commit comments

Comments
 (0)