12 Matching Annotations
  1. Jul 2019
    1. 3.8.

      apparently the last section(Balancing Symbols(a general case) page is not working, giving error 404, I don't know to whom to notify it, but yeah it's broken

    1. peek()

      Calling the element [-1] should work, but if a peek function is absolutely necessary one can define one, or if it's really important for the thing to behave more as a stack, it is easy to create a class using list as a superclass, and just adding peek as an internal function, and you can even make a push function that just calls the append.

      def peek_stack(stack): if stack == []: return None else: return stack[-1] # this will get the last element of stack

    2. push(item)

      can be replaced easily with append

    3. Stack()

      It looks like python 3 does not have an stack class, and just uses lists as stacks

  2. Jun 2019
    1. Timer

      should be timeit.Timer

    2. To use timeit you create a Timer object whose parameters are two Python statements. The first parameter is a Python statement that you want to time; the second parameter is a statement that will run once to set up the test.

      I did not understand very well how to define such object, and how to use it in the context of the codeblock following it, I would appreciate any help about it.

  3. May 2019
  4. Mar 2019
    1. print(self.num,"/",self.den)

      i particularly like an alternate construction better, because it allows you better control of the output string(this example will not insert spaces before and after the slash, unless you deliberately put them there)


      It uses the .format module, that lets you replace {} structures with the print verions of variables, you can set names for them like

      print('{numerator}/{denominator}'.format(denominator = self.den, numerator = self.num))

      and a lot of other stuff, you can learn more reading the python documentation of the string class

  5. Feb 2019
    1. list comprehension

      Black magic of making math inside of a list variable creation

    2. Modify the code from Activecode 8 so that the final list only contains a single copy of each letter

      the in can be used to check if somethings is in another set

    3. each value will be assigned to the variable item

      how the variable of the for statement works