How to sort a list based on another list with integers Python
<p>So, I'm generally new at programming, and I was just wondering if it was possible to sort a list based not on the positions of another list, but the actual integers itself?</p>

<pre><code>#Here is my list to be sorted
sent = ['Ho','Hi','Hi','Ho','Hi','Ho','!','Hi']

#The positions I will sort by
pos = [1, 2, 2, 1, 1, 1, 3]

#The output I want is
sortlst = ['Hi','Ho','Ho','Hi','Hi','Hi','Ho','!']
</code></pre>

<p>I have tried searching for methods to resolve this, but could not find any. List comprehensions and the like has been able to call elements in sent, but not by the actual integers of pos, rather the position.</p>

<pre><code>for i in pos:
    T.append(sent[i])
recreate = " ".join(T) 
print (recreate)
</code></pre>

<p>Running this segment will output:</p>

<pre><code>Ho Ho Ho Ho Ho Ho Ho Hi
</code></pre>

<p>Any help would be greatly appreciated!</p>

<p>You can try something like that:</p>

<pre><code>sent = ['Hi', 'Ho', '!']
pos = [1, 2, 2, 1, 1, 1, 3]
recreate = [sent[i - 1] for i in pos]
print(recreate)
# ['Hi', 'Ho', 'Ho', 'Hi', 'Hi', 'Hi', '!']
</code></pre>

<p>However it requires you to describe the table with 'signs' (<code>sent = ['Hi', 'Ho', '!']</code> here) that would be matched in order with numbers. 1 to 'Hi', 2 to 'Ho' and 3 to '!', etc. </p>

python