COMPSCI 101L Chapter Notes - Chapter 4, 6, 9-10: Substring, Empty String, Lexicographical Order

49 views3 pages
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
Unlock document

This preview shows page 1 of the document.
Unlock all 3 pages and 3 million more documents.

Already have an account? Log in

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions