## #StackBounty: #lists #exercises How can line breaks be suppressed in subQuestions using Exercise?

### Bounty: 100

The answers to sub-questions are often short: a) 2, b) -15, c) 21
How can I force a no-line-break for any given sub question?
MWE follows

``````%
%--------------------------------------------------------------------------------------------------------- %
documentclass{book}
%--------------------------------------------------------------------------------------------------------- %
%
usepackage[fleqn]{amsmath} %
usepackage{amsthm,amssymb} %
usepackage[paperwidth=170mm,paperheight=240mm,textwidth=132mm,driver=none,lmargin=25mm,vmargin=20mm,showframe,showcrop]{geometry} % verbose,showcrop,showframe=inner frame
usepackage[a4,frame,center]{crop} % pageframe
%
setlength{marginparsep}{0mm} %
%
renewcommand{subQuestionNB}{alph{subQuestion}) }

parnopagebreakmedskip}

setlength{subQuestionIndent}{16.8pt}

renewcounter{Exercise}[chapter] % Reset counter every chapter
newcounter{Problem}[chapter] %
%
%
begin{document}

begin{Exercise}[label={E1},name={Exercises on chapter},counter={Problem}]
Question{What is the symbol for iron?}
Question{What is the symbol for hydrogen?}
end{Exercise}

begin{Exercise}[label={E2},name={Exercises on chapter},counter={Problem}]
Question{What is the symbol for iron?}
Question{For hydrogen, state the following:}
subQuestion{the valency?} subQuestion{the atomic number?} subQuestion{the density?}
end{Exercise}

Question{Fe}
Question{H}

Question{Fe}
Question{}
subQuestion{2}
subQuestion{1 - Want this answer to follow on same line as (a)}
subQuestion{small - and this answer, too}

end{document}
``````

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