python: how to return 2 columns/index in a list
<p>I have a list that I generated using a for loop. it returns:</p>

<pre><code>home1-0002_UUID    3457077784  2132011944  1307504896  62%
home1-0003_UUID    3457077784  2088064860  1351451980  61%
home1-0001_UUID    3457077784  2092270236  1347246604  61%
</code></pre>

<p>How can I return only the third and fifth columns?</p>

<p>EDIT
when I get an error it says 'Nonetype' object is not iterable</p>

<pre><code> for index, elem in enumerate(my_list):
    print (index,elem)
</code></pre>

<p>I also tried to get the index by using  list(enumerate(my_list)) but it doesn't work I get TypeError: 'NoneType' object is not iterable</p>

<p>this is how I populate the list:</p>

<pre><code>def h1ost():
    p1 = subprocess.Popen("/opt/lustre-gem_s/default/bin/lfs df /lustre/home1 | sort -r -nk5",stdout=subprocess.PIPE, shell=True)
    use = p1.communicate()[0]
    for o in use.split('\n')[:6]:
        if "Available" not in o and "summary" not in o:
            print (o)
</code></pre>

<p>As far as I cannot post a comment I will do my best to give you a solution to the question.</p>

<pre><code>def empty_string_filter(value):
    return value != ''

def h1ost():
    p1 = subprocess.Popen("/opt/lustre-gem_s/default/bin/lfs df /lustre/home1 | sort -r -nk5",stdout=subprocess.PIPE, shell=True)
    use = p1.communicate()[0]
    new_file_content_list = [] 
    # Separate by line break and filter any empty string
    filtered_use_list = filter(empty_string_filter, use.split(os.linesep)[:6])
    for line in filtered_use_list :
        # Split the line and filter the empty strings in order to keep only
        # columns with information
        split_line = filter(empty_string_filter, line.split(' '))
        # Beware! This will only work if each line has 5 or more data columns
        # I guess the correct option is to check if it has at least 5 columns
        # and if it hasn't do not store the information or raise an exception. 
        # It's up to you.

        new_file_content_list.append('{0} {1}'.format(split_line[2] , split_line[4]))

    return os.linesep.join(new_file_content_list)
</code></pre>

<p>So the idea is split every single line by white spaces and filter any empty string left in order to get the 3rd and 5th column (index 2 and 4 respectively)</p>

python