sorted function (list/tuple) working wrongly in reverse order
Date : March 29 2020, 07:55 AM
wish helps you It appears to be working correctly. You're sorting by strings and, alphabetically, '8%' is considered greater than '26%'. You may find this more useful as your lambda: lambda x : float(x[1].strip('%'))

Will you get descending order if you reverse list of objects which is sorted by ascending order?
Date : March 29 2020, 07:55 AM
Hope that helps Yes, reversing a list, that is sorted in ascending order, will give you list that is sorted in descending order. However, it may not give you the same result as sorting a list in descending order.

How to traverse a sorted set in Redis in reverse order using zscan?
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Scanning the Sorted Set with an iterator does not guarantee any order. Use ZREVRANGEBYSCORE for that.

Python  printing out a trie in alphabetically sorted order with a recursive function
Tag : python , By : FarmerDave
Date : March 29 2020, 07:55 AM
it helps some times I'm working my way through the NLTK book by Bird, Klein, and Loper and I'm stuck on a problem. I'm working through the book for my own personal enrichment, and not for a class. def insert(trie, key, value):
"""Insert into Trie"""
if key:
first, rest = key[0], key[1:]
if first not in trie:
trie[first] = {}
insert(trie[first], rest, value)
else:
trie['value'] = value
def display(trie, s = ""):
"""Recursive function to Display Trie entries in alphabetical order"""
first = True
for k, v in sorted(trie.items(), key = lambda x: x[0]):
# dictionary sorted based upon the keys
if isinstance(v, dict):
if first:
prefix = s + k # first to show common prefix
first = False
else:
prefix = ''*len(s) + k # dashes for common prefix
display(v, prefix) # s+k is extending string s for display by appending current key k
else:
print(s, ":", v) # not a dictionary, so print current # not a dictionary, so print current string s and value
# Create Trie
trie = {}
insert(trie, 'chat', 'cat')
insert(trie, 'chien', 'dog')
insert(trie, 'chair', 'flesh')
insert(trie, 'chic', 'stylish')
#Display Use Recursive function (second argument will default to "" on call)
display(trie)
chair : flesh
t : cat
ic : stylish
en : dog

How to recognize that ndb query is sorted and how to reverse sort order without knowledge of sort order?
Tag : python , By : Matt Leacock
Date : March 29 2020, 07:55 AM

