How do I put a string in a list at every nth index?
<p>I'm working on a function that gets the suit and value as a string in a list from another function:</p>

<pre><code>def getCard(n):
    deckListSuit = []
    grabSuit = getSuit(n)
    n = (n-1) % 13 + 1
    if n == 1:
        deckListSuit.append("Ace")
        return deckListSuit + grabSuit
    if 2 &lt;= n &lt;= 10:
        deckListSuit.append(str(n))
        return deckListSuit + grabSuit
    if n == 11:
        deckListSuit.append("Jack")
        return deckListSuit + grabSuit
    if n == 12:
        deckListSuit.append("Queen")
        return deckListSuit + grabSuit
    if n == 13:
        deckListSuit.append("King")
        return deckListSuit + grabSuit
</code></pre>

<p>With the new function it is to take the information from the above function and return it in a list with a certain structure "VALUE of SUIT".</p>

<p>So say if you had "3", "Spades" it would return "3 of Spades" instead.</p>

<p>This is my code so far on the new function.</p>

<pre><code>def getHand(myList):
    hand = []
    for n in myList:
        hand += getCard(n)
    return [(" of ".join(hand[:2]))] + [(" of ".join(hand[2:4]))] + [(" of ".join(hand[4:6]))] + [(" of ".join(hand[6:8]))] + [(" of ".join(hand[8:10]))]
</code></pre>

<p>My question is, is how do I insert "of" between the value and suit without having to do .join a million times?</p>

<p>You can do it in your <code>for</code> loop</p>

<pre><code>for n in myList:
    hand += [" of ".join(getCard(n))]

return hand
</code></pre>

<p>You can also do it in <code>getCard</code> and return <code>'3 of Spades'</code></p>

<hr>

<p>BTW: you could keep it as tuples on list </p>

<pre><code>hand = [ ("3", "Spades"), ("Queen", "Spades"), ... ]
</code></pre>

<p>then you can use <code>for</code> loop instead of slices <code>[:2]</code>, <code>[2:4]</code></p>

<pre><code>new_list = []
for card in hand: 
    # in `card` you have ("3", "Spades")
    new_list.append(' of '.join(card))

return new_list
</code></pre>

python list python-3.x join