CSE 163
Lists and Files
Suh Young Choi�
🎶 Listening to: Max LL
💬 Before class: Happy Friday! How has your first week been?
This Time
Last Time
2
Quick Announcements!
3
Additional Note on CP and THA
4
Recap: Lesson
File processing
Lists
File paths
Jupyter Notebooks (briefly)
5
Files
6
with open(file_name) as f:
lines = f.readlines()
for line in lines:
# do something with line
with open(file_name) as f:
lines = f.readlines()
for line in lines:
words = line.split()
for word in words:
# do something with word
Strings
vs.
Lists
7
s = 'hello world'
# Length
len(s) # 11
# Indexing
s[1] # 'e'
s[len(s) - 1] # 'd'
# Looping
for i in range(len(s)):
print(s[i])
for c in s:
print(c)
l = ['dog', 'says', 'woof']
# Length
len(l) # 3
# Indexing
l[1] # 'says'
l[len(l) - 1] # 'woof'
# Looping
for i in range(len(l)):
print(l[i])
for word in l:
print(word)
Advanced Lists
8
words = ['I', 'love', 'dogs']
if 'dogs' in words:
print('Found it')
if 'cats' not in words:
print('Not there')
Group Work:
Best Practices
When you first working with this group:
Tips:
9
Before Next Time
Next Time
10