wk0.1 A curious case of conditionals

Intro to git and github

Read these:

A few challenges

Complete reverse_string and primes challenges in challenge folder.

Reviewing some ideas from yesterday

# Example from yesterday def t(num): if 10 <= num < 15: print("hot") elif num > 15: print("hotter") else: print("cold") # What does this function do? for i in range(4): for j in range(10): if j % 3 == 0: continue if j > 7 and j % 2 == 0: break else: print('i equals', i) print('j equals', j) print('------------')

While Conditional.: return discussion

more on conditionals:

Try evaluating each of the lines below in your python REPL. What's going on?

a = [1, 2, 3]
b = a
b is a
b == a
b = a[:]
b is a
b == a

If you have a hypothesis about the difference between is and ==, devise some tests you could try out to disprove your hypothesis. Implement them. Were you correct?

  • in and not in
  • and, or
  • comparison priority

    not has the highest priority and or the lowest, so that A and not B or C is equivalent to (A and (not B)) or C.

  • Short circuit operators

More string and list practice

  • Add elements from a list L to the end of another list at least three different ways.
  • Insert elements into a list at least two different ways.
  • Insert an element into a string (this might take more than one step...).
  • Remove an item from a list by value.
  • Remove an item from a list by index.
  • Remove all items from a list two different ways.
  • Return the index in the list of the first item whose value is x.
  • Return the number of times x appears in the list.
  • Capitalize the first element in a string
  • Capitalize all elements in a string
  • Strip leading, trailing, and all whitespace (ex. leading: ' asdf ' --> 'asdf ', trailing:' asdf ' --> ' asdf', all:' asdf ' --> 'asdf').
  • Split a sentence into a list of words (no whitespace), how would you split on comma or semi-colon?
  • Read up on how to format strings