title: Python join list of strings with comma but with some conditions - code refractoring
body: <p>Assume i have this list <code>l</code>:</p>
  
  <pre><code>l = ['a', 'b', 'c', 'd', 'e']
  </code></pre>
  
  <p>I know i can join them using <code>.join</code> with comma separated as:</p>
  
  <pre><code>s = ', '.join(l)
  &gt;&gt;&gt; a, b, c, d, e
  </code></pre>
  
  <p>But i want to respect these conditions while joining, few cases are:</p>
  
  <ul>
  <li>If <code>len(l) == 1</code> then output should be just <code>a</code></li>
  <li>if <code>len(l) == 2</code> then output should be <code>a and b</code></li>
  <li>if <code>len(l) &gt; 2 and len(l) &lt; 5</code> then output should be <code>a, b, c and d</code></li>
  <li>if <code>len(l) &gt;= 5</code>:
  <ul>
  <li>if <code>len(l) == 5</code> then output should be <code>a, b, c, d and 1 other</code></li>
  <li>if <code>len(l) &gt; 5</code> then output should be <code>a, b, c, d and +(number of remaining strings) others</code></li>
  </ul></li>
  </ul>
  
  <p>What i have tried (working):</p>
  
  <pre><code>def display(l, threshold=4):
      s = ''
      if l:
          c = len(l)
          if c &lt;= threshold:
              if c == 1:
                  s = l[0]
              else:
                  s = ', '.join(l[:-1])
                  s += ' and ' + l[-1]
          else:
              s = ', '.join(l[:threshold])
              remaining = c - threshold
              other = 'other' if remaining == 1 else 'others'
              remaining = str(remaining) if remaining == 1 else '+' + str(remaining)
              s += ' and %s %s' % (remaining, other)
          print s
      return s
  
  if __name__ == '__main__':
      l = ['a', 'b', 'c', 'd', 'e', 'f']
      display(l[:1])
      display(l[:2])
      display(l[:3])
      display(l[:4])
      display(l[:5])
      display(l)
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>a
  a and b
  a, b and c
  a, b, c and d
  a, b, c, d and 1 other
  a, b, c, d and +2 others
  </code></pre>
  
  <p>Can this code be improved and refractor? </p>