Skip to content

Commit 9054b2b

Browse files
committed
Updated string funcs, list lab.
1 parent 25147be commit 9054b2b

3 files changed

Lines changed: 34 additions & 9 deletions

File tree

‎Students/ebuer/session_03/s3_notefile.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
Session 03 notes from class
2+
---------------------------------
3+
String
24
ord () is the ordinal of a string value. This allows us to quickly alphabetize strings. Cap letters are indexed in front of lower case.
35

46
string.index() locates the first instance of a specified string passed to the operator.
Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,41 @@
11
#@python: 2
2+
#slicing lab functions
23

3-
test_string = 'The quick brown fox jumped over the lazy dog'
4-
test_string2 = 'Relaxing in basins at the end of inlets \
5-
terminates the endless tests from the box'
4+
test_string = 'The quick brown fox jumps over the lazy dog'
5+
test_string2 = 'Pack my box with five dozen liquor jugs'
6+
test_string3 = [0, 1, 1, 2, 3, 5, 8, 13]
67

78

8-
def switcher(str):
9-
return str[-1] + str[1:-1] + str[0]
9+
#first and last characters exchanged
10+
def switcher(t_str):
11+
return '%s%s%s' %(t_str[-1], t_str[1:-1],t_str[0])
1012

1113

12-
def skipper(str):
13-
return str[0:50:2]
14+
#ever other character
15+
def skipper(t_str):
16+
return t_str[::2]
1417

18+
#first 4 and last 4 chars removed, every other in between
19+
def hacker(t_str):
20+
return t_str[4:-4:2]
1521

16-
ans = skipper(test_string2)
17-
print (ans)
22+
23+
#reverse a string using slicing
24+
def reverso(t_str):
25+
return t_str[::-1] #whole string, step/walk backwards
26+
27+
#return middle, last, first thirds of random string
28+
def scrambler(t_str):
29+
temp = len(t_str)
30+
front = t_str[0:temp / 3]
31+
mid = t_str[temp / 3 : 2 * temp / 3]
32+
last = t_str[2 * temp /3 :]
33+
return '%s%s%s' %(mid, last, front)
34+
35+
#printing block
36+
print switcher(test_string)
37+
print skipper(test_string3)
38+
print hacker(test_string2)
39+
print reverso(test_string2)
40+
print scrambler(test_string)
1841

0 commit comments

Comments
 (0)