#StackBounty: #command-line #keyboard #python3 #readline Using readline in python3 (input) pressing arrows will remove text from the in…

Bounty: 50

My input code is:

import readline
readline.parse_and_bind('tab: complete')
readline.parse_and_bind('set editing-mode vi')

while True:
     c = input('INPUT> ')

(It is a little piece of test code to test readline.)

When i type abc ENTER Hello, World! ENTER and 2x arrow up instead of

INPUT>abc

It is INabc

Does anyone know how to fix this?

(I already tried commenting out the readline.parse_and_bind’s I also use updated python3 and updated my readline using pip3, which also it up to date. And my readline is for python3. And everything is up to date!)


Get this bounty!!!

Sort a list of tuples by Nth item in Python

Suppose you have a list of tuples that looks something like this:

[('abc', 121),('abc', 231),('abc', 148), ('abc',221)]

And you want to sort this list in ascending order by the integer value inside the tuples.

We can achieve this using the key keyword with sorted().

sorted([('abc', 121),('abc', 231),('abc', 148), ('abc',221)], key=lambda x: x[1])

key should be a function that identifies how to retrieve the comparable element from your data structure. For example, the second element of the tuple, so we access [1].

Source: StackOverflow.com