remove all elements in a list not relatively prime
Question: I have a list `m` in python, and I want to remove all the elements in m that
are not relatively prime to all previous elements. So if `m=[2,3,4]` I want
the output to be `[2,3]`.

I tried iterating through the values of `m`, but it doesnt work since the size
of `m` changes and then the index value is out of range.


Answer: You can use
[`enumerate`](https://docs.python.org/3/library/functions.html#enumerate) and
[`any`](https://docs.python.org/3/library/functions.html#any) within a list
comprehension and use `fractions.gcd` function to get the gcd for each pairs :

    
    
    >>> from fractions import gcd
    >>> [j for i,j in enumerate(m) if not any(gcd(j,t)!=1 for t in m[:i])]
    [3, 100, 7, 11, 17]
    

Also as @mgilson mentioned in comment as a more efficient way instead of
simple slicing in `any` you can use `itertools.islice` function.

