### This is the result of the interpreter for all of the lists videos.
# Python 3.8.5 (default, Jul 21 2020, 10:48:26)
# [Clang 11.0.3 (clang-1103.0.32.62)] on darwin
# Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>> courses = [ 'CS88', 'DATA8' ]
>>> courses
['CS88', 'DATA8']
>>> courses[0]
'CS88'
>>> courses[1]
'DATA8'
>>> courses[2]
Traceback (most recent call last):
File "", line 1, in
IndexError: list index out of range
>>> len(courses)
2
>>> course += [ 'POLSCI2', 'PHILR1B']
Traceback (most recent call last):
File "", line 1, in
NameError: name 'course' is not defined
>>> courses += [ 'POLSCI2', 'PHILR1B']
>>> courses
['CS88', 'DATA8', 'POLSCI2', 'PHILR1B']
>>> len(courses)
4
>>>
>>>
>>>
>>> numbers = [ 1, 2, 3, 4, 5]
>>> sum(number)
Traceback (most recent call last):
File "", line 1, in
NameError: name 'number' is not defined
>>> sum(numbers)
15
>>> min(numbers)
1
>>>
>>>
>>>
>>>
>>> courses
['CS88', 'DATA8', 'POLSCI2', 'PHILR1B']
>>> numbers
[1, 2, 3, 4, 5]
>>> courses[1]
'DATA8'
>>> courses[2]
'POLSCI2'
>>> courses[3]
'PHILR1B'
>>> for item in courses:
... print(item)
...
CS88
DATA8
POLSCI2
PHILR1B
>>> for number in numbers:
... print(number * 2)
...
2
4
6
8
10
>>>
>>>
>>>
>>> range(10)
range(0, 10)
>>> for number in range(10):
... print(number)
...
0
1
2
3
4
5
6
7
8
9
>>> range(len(courses))
range(0, 4)
>>> for number in range(len(courses)):
... print(courses[number])
...
CS88
DATA8
POLSCI2
PHILR1B
>>> for number in range(0, 10, 2):
... print(number)
...
0
2
4
6
8
>>>
>>>
>>>
>>> list(range(2, 19, 3)))
File "", line 1
list(range(2, 19, 3)))
^
SyntaxError: unmatched ')'
>>> list(range(2, 19, 3))
[2, 5, 8, 11, 14, 17]
>>> range(2, 19, 3)
range(2, 19, 3)
>>> range(0, 1000000000000000000000000000000, 2)
range(0, 1000000000000000000000000000000, 2)
>>>
>>>
>>> print(s) for s in 'CS88'
File "", line 1
print(s) for s in 'CS88'
^
SyntaxError: invalid syntax
>>> [ print(s) for s in 'CS88' ]
C
S
8
8
[None, None, None, None]
>>>
>>>
>>>
>>> sum(i * 2 for i in range(10))
90
>>> sum(i * 2 for i in range(10) if i % 2 == 1)
50
>>>
>>>
>>>
>>> [print('I like '+ course) for course in courses ]
I like CS88
I like DATA8
I like POLSCI2
I like PHILR1B
[None, None, None, None]
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> courses
['CS88', 'DATA8', 'POLSCI2', 'PHILR1B']
>>> numbers
[1, 2, 3, 4, 5]
>>> for course in courses:
... print(course)
...
CS88
DATA8
POLSCI2
PHILR1B
>>>
>>> [ course for course in courses ]
['CS88', 'DATA8', 'POLSCI2', 'PHILR1B']
>>> [ i ** 2 for i in numbers ]
[1, 4, 9, 16, 25]
>>> courses_copy = [ course for course in courses ]
>>> squared = [ i ** 2 for i in numbers ]
>>> squared
[1, 4, 9, 16, 25]
>>> sum(squared)
55
>>> ( i ** 2 for i in numbers)
at 0x109a64eb0>
>>> sum( i ** 2 for i in numbers)
55
>>>
>>>
>>>
>>> squared = []
>>> squared
[]
>>> for i in numbers:
... squared.append(i ** 2)
...
>>> squared
[1, 4, 9, 16, 25]
>>>
>>>
>>>
>>>
>>> numbers
[1, 2, 3, 4, 5]
>>> numbers = list(range(20))
>>>
>>> num
number numbers
>>> numbers
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
>>> [ i ** 2 for i numbers if i % 2 == 0 ]
File "", line 1
[ i ** 2 for i numbers if i % 2 == 0 ]
^
SyntaxError: invalid syntax
>>> [ i ** 2 for i in numbers if i % 2 == 0 ]
[0, 4, 16, 36, 64, 100, 144, 196, 256, 324]
>>> len([ i ** 2 for i in numbers if i % 2 == 0 ])
10
>>> courses
['CS88', 'DATA8', 'POLSCI2', 'PHILR1B']
>>> len(courses[2])
7
>>> [ course for course in courses if len(course) < 5 ]
['CS88']
>>> [ word[0] for word in courses ]
['C', 'D', 'P', 'P']
>>> [ letter for letter in courses[0] ]
['C', 'S', '8', '8']
>>>