This repository was archived by the owner on Feb 14, 2024. It is now read-only.
Some small tweaks while reading the code#37
Open
guoqiao wants to merge 4 commits intojuju-solutions:masterfrom
Open
Some small tweaks while reading the code#37guoqiao wants to merge 4 commits intojuju-solutions:masterfrom
guoqiao wants to merge 4 commits intojuju-solutions:masterfrom
Conversation
In py2:
sorted(iterable[, cmp[, key[, reverse]]])
In py3:
sorted(iterable, *, key=None, reverse=False)
The `cmp` arg is removed in py3.
Also, it's much slower than `key` since `cmp` is called multiple times
for each list element(O(n^2)), while `key` touch each element only once(O(n)).
Replace `cmp` with `key` as a keyword arg, this make `sorted` faster and
also python 2/3 compatible.
Signed-off-by: Joe Guo <guoqiao@gmail.com>
In py2:
dict.items() -> list
dict.iteritems() -> iterator
iteritems() is preferred for less memory usage in py2.
In py3:
dict.items() -> iterator
dict.iteritems() -> removed
Use items() instead of iteritems(), to be python 2/3 compatible.
In py2, the returned list may use more memory, but shouldn't be problem
in this case.
Didn't use six, which is unnecessary here and introduce noise in code.
Signed-off-by: Joe Guo <guoqiao@gmail.com>
make use of maxsplit arg to get db name and the rest in one line. Signed-off-by: Joe Guo <guoqiao@gmail.com>
make use of defaultdict(dict) to avoid key check each time. Signed-off-by: Joe Guo <guoqiao@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Small improvements, could be worthy.