Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Python sorted comparator

$
0
0

I am trying to sort a list of tuples on the lexicographic order of the sub-string that the tuples are indicating.

In the following case, I wish to sort a which actaully represents ["sd", "dce", "ces"]. I'm not sure how to use the comparator to achieve this.

def cmp(key, text):    return text[key[0]:key[1]+1]a = [(1,2), (2, 4), (3, 5)]text = "asdcesa"sorted(a, key=cmp(text))

The above code would give this error "cmp() missing 1 required positional argument: 'text'"


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>