Closed gurukiran07 closed 3 years ago
That's an accurate observation. Counter
might be a bit too much of a black box for some readers, but you might be onto something with the defaultdict
implementation. Only thing I'd change in that one would be the return
statement to wrap the result in a dict()
call. Other than that, I think that's a valid way to improve the snippet, so feel free to PR it.
really great improvement
Counter might be a bit too much of a black box for some readers @Trinityyi
Yes, agreed.
Only thing I'd change in that one would be the return statement to wrap the result in a dict() call
Okay, will do.
And I made a partial list of questions(will prepare the whole list in a day or two) that are frequently asked on StackOverflow, should I post the list in another issue where we can scrutinize the proposed questions?
@gurukiran07 Sure, you can open an issue and we might start tackling them one by one.
In
frequencies.md
, the time complexity isO(n^2)
.list.count()
's complexity isO(n)
, usinglist.count
n
times, making it quadratic time.We can use
collections.Counter
which does it inO(n)
.Using
collection.defaultdict
All the above mentioned are
O(n)
run time functions. Please select whichever you see fit.