title: The right and elegant way to split a join a string in Python
body: <p>I have the following list:</p>
  
  <pre><code>&gt;&gt;&gt; poly
  'C:\\04-las_clip_inside_area\\16x16grids_1pp_fsa.shp'
  &gt;&gt;&gt; record
  1373155
  </code></pre>
  
  <p>and I wish to create:</p>
  
  <pre><code>'C:\\04-las_clip_inside_area\\16x16grids_1pp_fsa_1373155.txt'
  </code></pre>
  
  <p>I wish to split in order to get the part "C:\04-las_clip_inside_area\16x16grids_1pp_fsa16x16grids_1pp_fsa".</p>
  
  <p>I have tried this two-code-lines solution:</p>
  
  <pre><code>mylist = [poly.split(".")[0], "_", record, ".txt"]
  &gt;&gt;&gt; mylist
  ['C:\\04-las_clip_inside_area\\16x16grids_1pp_fsa', '_', 1373155, '.txt']
  </code></pre>
  
  <p>from here, reading the example in <em><a href="https://stackoverflow.com/questions/493819/python-join-why-is-it-string-joinlist-instead-of-list-joinstring">Python join, why is it string.join(list) instead of list.join(string)?</a></em>.</p>
  
  <p>I find this solution to joint, but I get this error message:</p>
  
  <pre><code>&gt;&gt;&gt; mylist.join("")
  Traceback (most recent call last):
    File "&lt;interactive input&gt;", line 1, in &lt;module&gt;
  AttributeError: 'list' object has no attribute 'join'
  </code></pre>
  
  <p>Also if I use:</p>
  
  <pre><code>&gt;&gt;&gt; "".join(mylist)
  Traceback (most recent call last):
    File "&lt;interactive input&gt;", line 1, in &lt;module&gt;
  TypeError: sequence item 2: expected string, int found
  </code></pre>