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
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
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
push(item)
can be replaced easily with append
Stack()
It looks like python 3 does not have an stack class, and just uses lists as stacks
Timer
should be timeit.Timer
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.
%10.7f
what the hell is happening here?
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)
print('{}/{}'.format(self.num,self.den))
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
eferences to the data objects in the sequence.
That is so weird
list comprehension
Black magic of making math inside of a list variable creation
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
each value will be assigned to the variable item
how the variable of the for statement works