COMPSCI 101L Chapter Notes - Chapter 4, 6, 9-10: Substring, Empty String, Lexicographical Order
Computer Science
Reading Notes ā Chapter 4.7-4.11, 6.5, 9.8-9.16, 10.1-10.14
Chapter 4
- Range (4) produces the sequence [0, 1, 2, 3]
- You can also have a start and stop value
o Range (1, 5) produces [1, 2, 3, 4]
- You can also have a step value
o Range (0, 9, 2) produces [0, 2, 4, 6, 8]
- You can also create a list in decreasing order
o Range (10, 0, -1) produces [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
Chapter 6
- Accumulator pattern: pattern of iterating the updating of a variable
Chapter 9
- You can use comparison operators for putting words in lexicographical order (same
thing as alphabetical order except uppercase is before lowercase)
o Ex: īzebraī > ībananaī
o Eī: īDogī < īDoghouseī īeīause īDogī is shorter
- The way that the program can do this is that each character is assigned a unique integer
value or īordiī
¶al īalueī
o Eī: ordī¾īAīīæ is ī²ī± aī
¶d ordī¾īaīīæ is 9ī³
o Ex: chr(65) converts ordinal values to their character
- Strings are immutable
o You cannot change an existing string, but you can try to create a new string
- Since a string a sequence of characters, the for loops iterates over each character
o Eī: for aīhar iī
¶ īGo āpot Goī:
āŖ Print(achar) will result in every line having a character from the sequence
- The in operator tests if one string is a substring of another
o Eī: priī
¶tī¾īoī iī
¶ īappleīīæ īill īe False
o Not in is also an operator
Chapter 10
- Parts of the list are elements
- In Python, every object has a unique identification tag
o Fuī
¶ītioī
¶ id alloīs īou to fiī
¶d the oījeītīs tag
- + concatenates lists
- Lists are mutable
o alist = ['a', 'b', 'c', 'd', 'e', 'f']
o alist[1:3] = ['x', 'y']
o print(alist)
o The above example changes c and d to x and y
find more resources at oneclass.com
find more resources at oneclass.com
Document Summary
Reading notes chapter 4. 7-4. 11, 6. 5, 9. 8-9. 16, 10. 1-10. 14. Range (4) produces the sequence [0, 1, 2, 3] You can also have a start and stop value: range (1, 5) produces [1, 2, 3, 4] You can also have a step value: range (0, 9, 2) produces [0, 2, 4, 6, 8] You can also create a list in decreasing order: range (10, 0, -1) produces [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] Accumulator pattern: pattern of iterating the updating of a variable. You can use comparison operators for putting words in lexicographical order (same thing as alphabetical order except uppercase is before lowercase: ex: (cid:862)zebra(cid:863) > (cid:862)banana(cid:863, e(cid:454): (cid:862)dog(cid:863) < (cid:862)doghouse(cid:863) (cid:271)e(cid:272)ause (cid:862)dog(cid:863) is shorter. The way that the program can do this is that each character is assigned a unique integer value or (cid:862)ordi(cid:374)al (cid:448)alue(cid:863: e(cid:454): ord(cid:894)(cid:862)a(cid:863)(cid:895) is (cid:1010)(cid:1009) a(cid:374)d ord(cid:894)(cid:862)a(cid:863)(cid:895) is 9(cid:1011, ex: chr(65) converts ordinal values to their character.