Python-remove duplicate output

dieter dieter at handshake.de
Thu Nov 22 02:20:21 EST 2018


drvucanovic at gmail.com writes:

> How to remove duplicate lines and store output into one ine

I do not understand "into one ine".

> ...
> Current Output:
> aws-opsworks
> aws-opsworks Ansible
>
> Desired output:
> aws-opsworks Ansible

Looks for me as if you do not want to remove duplicate lines:
in your example, there are no duplicate lines - there is
only a duplicate word.


To get the task done, it is vital to clearly understand it.

If "into one ine" should in fact mean "into one line",
then your task *MIGHT* in fact be:

 * split each input line into words (at space boundaries)
 * omit duplicate words
 * return a line containing the unique words

Then the solution could somehow look like:
 * you have a list "words", initially empty.
 * you iterate over your input
   - you split the input line into words
   - for each word, you check whether it is already in "words"
     and otherwise append it
 * you join "words" together to form the result line




More information about the Python-list mailing list