Skip to content

Other stackoverflow problems

flian2 edited this page Jan 26, 2018 · 1 revision
if __name__ == '__main__':
    N = int(raw_input())
    res = []
    for i in range(0, N):
        line = raw_input()
        ops = line.split(' ')
        if ops[0] == "print":
            print res
        else:
            func = getattr(list, ops[0])
            oprands = ops[1:]
            if len(oprands) == 0:
                func(res)
            else:
                oprands = [int(num) for num in oprands]
                func(res, *oprands)

string.split() vs string.split(' ') When there are multiple spaces, the latter result can contain empty strings.


reduce() function explained https://stackoverflow.com/questions/13603361/python-reduce-explanation


Cast tuple as namedtuple https://stackoverflow.com/questions/25000159/how-to-cast-tuple-into-namedtuple



Other resources:

https://www.gitbook.com/book/taizilongxu/stackoverflow-about-python/details

Clone this wiki locally