Skip to content

Python Related

hyjing edited this page May 5, 2019 · 4 revisions

通过list创建一个dictionary

dict comprehension syntax (https://www.python.org/dev/peps/pep-0274/)
d = {key: value for (key, value) in iterable}

Python pass variable by reference? (in parameter)

Remember that arguments are passed by assignment in Python. Since assignment just creates references to objects, there’s no alias between an argument name in the caller and callee, and so no call-by-reference per se. You can achieve the desired effect in a number of ways. (https://docs.python.org/3/faq/programming.html#how-do-i-write-a-function-with-output-parameters-call-by-reference) https://stackoverflow.com/questions/986006/how-do-i-pass-a-variable-by-reference

LinkedList traversal

Can only modify node.next to change list (Ex. node.next = ListNode(0) works, but not node = ListNode(0))

Clone this wiki locally