Python 3.5.2 |Anaconda 4.1.1 (x86_64)| (default, Jul 2 2016, 17:52:12)
Type "copyright", "credits" or "license" for more information.
IPython 4.2.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
%guiref -> A brief reference about the graphical user interface.
In [1]: runfile('/Users/progprim/Desktop/code/fifoqueue_outline.py', wdir='/Users/progprim/Desktop/code')
In [2]: q
Out[2]: []
In [3]: add('Paul')
In [4]: q
Out[4]: ['Paul']
In [5]: q.insert?
Docstring: L.insert(index, object) -- insert object before index
Type: builtin_function_or_method
In [6]: q.extend?
Docstring: L.extend(iterable) -> None -- extend list by appending elements from the iterable
Type: builtin_function_or_method
In [7]: q
Out[7]: ['Paul']
In [8]: q.insert(0, "Mary")
In [9]: q
Out[9]: ['Mary', 'Paul']
In [10]: q.insert("Mary")
Traceback (most recent call last):
File "<ipython-input-10-270ee4b271ac>", line 1, in <module>
q.insert("Mary")
TypeError: insert() takes exactly 2 arguments (1 given)
In [11]: runfile('/Users/progprim/Desktop/code/fifoqueue_outline.py', wdir='/Users/progprim/Desktop/code')
In [12]: add('Paul'); add('Mary')
In [13]: show()
<list_reverseiterator object at 0x1195c1c18>
In [14]: runfile('/Users/progprim/Desktop/code/fifoqueue_outline.py', wdir='/Users/progprim/Desktop/code')
In [15]: add('Paul'); add('Mary')
In [16]: show()
['Mary', 'Paul']
In [17]: len(q)
Out[17]: 2
In [18]: q.remove?
Docstring:
L.remove(value) -> None -- remove first occurrence of value.
Raises ValueError if the value is not present.
Type: builtin_function_or_method
In [19]: q[1:]
Out[19]: ['Mary']
In [20]: q[0]
Out[20]: 'Paul'
In [21]: q.pop?
Docstring:
L.pop([index]) -> item -- remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.
Type: builtin_function_or_method
In [22]: q
Out[22]: ['Paul', 'Mary']
In [23]: q.pop(0)
Out[23]: 'Paul'
In [24]: q
Out[24]: ['Mary']
In [25]: runfile('/Users/progprim/Desktop/code/fifoqueue_outline.py', wdir='/Users/progprim/Desktop/code')
In [26]: add('Paul'); add('Mary')
In [27]: show()
['Mary', 'Paul']
In [28]: length()
Out[28]: 2
In [29]: next()
Out[29]: 'Paul'
In [30]: length()
Out[30]: 1
In [31]: show()
['Mary']
In [32]: next()
Out[32]: 'Mary'
In [33]: length()
Out[33]: 0
In [34]: next()
Traceback (most recent call last):
File "<ipython-input-34-b80b41363c01>", line 1, in <module>
next()
File "/Users/progprim/Desktop/code/fifoqueue_outline.py", line 26, in next
return q.pop(0)
IndexError: pop from empty list
In [35]: runfile('/Users/progprim/Desktop/code/fifoqueue_outline.py', wdir='/Users/progprim/Desktop/code')
In [36]: next()
The queue is empty.
In [37]: runfile('/Users/progprim/Desktop/code/fifoqueue-alternative.py', wdir='/Users/progprim/Desktop/code')
In [38]: add('Paul'); add('Mary')
In [39]: show()
['Mary', 'Paul']
In [40]: length()
Out[40]: 2
In [41]: next()
Out[41]: 'Paul'
In [42]: next()
Out[42]: 'Mary'
In [43]: runfile('/Users/progprim/Desktop/code/16_while.py', wdir='/Users/progprim/Desktop/code')
epsilon is 1.1102230246251565e-16
In [44]: eps + 1
Out[44]: 1.0
In [45]: 1 + 1e-16
Out[45]: 1.0
In [46]: 2*eps + 1
Out[46]: 1.0000000000000002
In [47]: [0, 2, 4, 6]
Out[47]: [0, 2, 4, 6]
In [48]: a = [0, 2, 4, 6]
In [49]: a
Out[49]: [0, 2, 4, 6]
In [50]: b = a
In [51]: b[1] = 10
In [52]: b
Out[52]: [0, 10, 4, 6]
In [53]: a
Out[53]: [0, 10, 4, 6]
In [54]: id(a)
Out[54]: 4720614664
In [55]: id(b)
Out[55]: 4720614664
In [56]: id(a) == id(b)
Out[56]: True
In [57]: a is b
Out[57]: True
In [58]: c = 1
In [59]: d = 1.0
In [60]: id(c)
Out[60]: 4297148528
In [61]: id(d)
Out[61]: 4720102040
In [62]: c is d
Out[62]: False
In [63]: c == d
Out[63]: True
In [64]: e = 1
In [65]: c is e
Out[65]: True
In [66]: id(c)
Out[66]: 4297148528
In [67]: id(e)
Out[67]: 4297148528
In [68]: e = 2
In [69]: id(e)
Out[69]: 4297148560
In [70]: a = 1*b
In [71]: a
Out[71]: [0, 10, 4, 6]
In [72]: b
Out[72]: [0, 10, 4, 6]
In [73]: a is b
Out[73]: False
In [74]: a = b[:]
In [75]: a is b
Out[75]: False
In [76]: c = 'This is my string'
In [77]: c.split()
Out[77]: ['This', 'is', 'my', 'string']
In [78]: c.split?
Docstring:
S.split(sep=None, maxsplit=-1) -> list of strings
Return a list of the words in S, using sep as the
delimiter string. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator and empty strings are
removed from the result.
Type: builtin_function_or_method
In [79]: c.split()
Out[79]: ['This', 'is', 'my', 'string']
In [80]: c
Out[80]: 'This is my string'
In [81]: c.split('i')
Out[81]: ['Th', 's ', 's my str', 'ng']
In [82]: runfile('/Users/progprim/Desktop/code/lecture4-shoppinglist.py', wdir='/Users/progprim/Desktop/code')
In [83]: !cat cost.txt
bread 1 1.39
tomatoes 6 0.26
milk 3 1.45
coffee 3 2.99
In [84]: runfile('/Users/progprim/Desktop/code/lecture4-shoppinglist.py', wdir='/Users/progprim/Desktop/code')
In [85]: !cat cost.txt
bread 1 1.39
testtomatoes 6 0.26
testmilk 3 1.45
testcoffee 3 2.99
test
In [86]: lines = open('shopping.txt', 'r').readlines()
In [87]: lines
Out[87]:
['bread 1 1.39\n',
'tomatoes 6 0.26\n',
'milk 3 1.45\n',
'coffee 3 2.99\n']
In [88]: processline(lines[0])
Out[88]: 'bread 1 1.39\ntest'
In [89]: data = lines[0]
In [90]: data
Out[90]: 'bread 1 1.39\n'
In [91]: data.split()
Out[91]: ['bread', '1', '1.39']
In [92]: int('1')
Out[92]: 1
In [93]: type(int('1'))
Out[93]: int
In [94]: float('3.14')
Out[94]: 3.14
In [95]: items = data.split()
In [96]: times
Traceback (most recent call last):
File "<ipython-input-96-490f60352181>", line 1, in <module>
times
NameError: name 'times' is not defined
In [97]: items
Out[97]: ['bread', '1', '1.39']
In [98]: price = int(items[1]) * float(items[2])
In [99]: price
Out[99]: 1.39
In [100]: price = int(items[-2]) * float(items[-1])
In [101]: price
Out[101]: 1.39
In [102]: "%10s %4.2f" % (items[0], price)
Out[102]: ' bread 1.39'
In [103]: "%s %4.2f" % (items[0], price)
Out[103]: 'bread 1.39'
In [104]: runfile('/Users/progprim/Desktop/code/lecture4-shoppinglist.py', wdir='/Users/progprim/Desktop/code')
In [105]: !cat costs.txt
cat: costs.txt: No such file or directory
In [106]: !cat cost.txt
bread 1.39tomatoes 1.56milk 4.35coffee 8.97
In [107]: runfile('/Users/progprim/Desktop/code/lecture4-shoppinglist.py', wdir='/Users/progprim/Desktop/code')
In [108]: !cat cost.txt
bread 1.39
tomatoes 1.56
milk 4.35
coffee 8.97
In [109]: items
Out[109]: ['bread', '1', '1.39']
In [110]: name, number, itemcost = items
In [111]: name
Out[111]: 'bread'
In [112]: number
Out[112]: '1'
In [113]: open('shopping.txt', 'rt').readlines()
Out[113]:
['bread 1 1.39\n',
'tomatoes 6 0.26\n',
'milk 3 1.45\n',
'coffee 3 2.99\n']
In [114]: