Answers.Body: <p>Assuming that the file <code>test.txt</code> is tab-separated values with these fields:</p>
  <pre><code>WP_XXXXXXXX2.1  PF06325     Ribosomal protein L11 methyltransferase (PrmA)      5
  WP_192XXXXXX.1  PF13489     Methyltransferase domain                            4
  XXXXXXX45.1     PF02310     B12 binding domain                                  12 
  XXXXXXX45.1     PF04055     Radical SAM superfamily                             5
  WP_XXXXXXX29.1  PF13489     Methyltransferase domain                            4
  WP_0XXXXXXXX.1  PF13489     Methyltransferase domain                            4
  WP_XXXXXXX90.1  PF06325     Ribosomal protein L11 methyltransferase (PrmA)      5
  WP_XXXXXXX90.1  PF06325     Ribosomal protein L11 methyltransferase (PrmA)      7
  WP_0XXXXXX62.1  PF13489     Methyltransferase domain                            4
  </code></pre>
  <p>You can proceed first by reading your file:</p>
  <pre><code>with open(&quot;test.txt&quot;,'r') as rf:
      l = rf.readlines() # all the lines are stored in variable 'l'
  </code></pre>
  <p>You should create a dictionary with your ID as keys and the remaining line as values:</p>
  <pre><code># create empty dictionary
  dict_id = {}
  
  for i in l:                                                               # for each line
      key_id = i.split(&quot;\t&quot;)[0]                                             # get the id
      if key_id not in dict_id.keys():                                      # if id as key is not found in dictionary
          value = &quot;\t&quot;.join(i.split(&quot;\t&quot;)[1:]).rstrip()                     # parse the value
          dict_id[key_id] = [value]                                         # add the id as key to dictionary with its value
      else:                                                                 # else if id as key is already in dictionary
          dict_id[key_id].append(&quot;\t&quot;.join(i.split(&quot;\t&quot;)[1:]).rstrip())     # append to id as key
  </code></pre>
  <p>And now, you can print the result:</p>
  <pre><code>for key, value in dict_id.items():         # for each key, values in dictionary
      print(key + &quot;: &quot; + &quot;; &quot;.join(value))   # print the key and their values separated by '; '
  </code></pre>
  <p>And you should obtain:</p>
  <pre><code>WP_XXXXXXXX2.1: PF06325 Ribosomal protein L11 methyltransferase (PrmA)  5
  WP_192XXXXXX.1: PF13489 Methyltransferase domain        4
  XXXXXXX45.1: PF02310    B12 binding domain      12; PF04055     Radical SAM superfamily 5
  WP_XXXXXXX29.1: PF13489 Methyltransferase domain        4
  WP_0XXXXXXXX.1: PF13489 Methyltransferase domain        4
  WP_XXXXXXX90.1: PF06325 Ribosomal protein L11 methyltransferase (PrmA)  5; PF06325      Ribosomal protein L11 methyltransferase (PrmA)  7
  WP_0XXXXXX62.1: PF13489 Methyltransferase domain        4
  </code></pre>
  <p>The final script:</p>
  <pre><code>with open(&quot;test.txt&quot;,'r') as rf:
      l = rf.readlines()
  
  dict_id = {}
  for i in l:
      key_id = i.split(&quot;\t&quot;)[0]
      if key_id not in dict_id.keys():
          value = &quot;\t&quot;.join(i.split(&quot;\t&quot;)[1:]).rstrip()
          dict_id[key_id] = [value] 
      else:
          dict_id[key_id].append(&quot;\t&quot;.join(i.split(&quot;\t&quot;)[1:]).rstrip())
  
  for key, value in dict_id.items():
      print(key + &quot;: &quot; + &quot;; &quot;.join(value))
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-26T14:12:10.473Z
Answers.Text: realy thanks :) all best
Answers.UserDisplayName: MTG
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-25T20:43:28.733Z
Answers.LastActivityDate: 2022-01-26T06:15:03.587Z
Answers.LastEditDate: 2022-01-26T06:15:03.587Z
Answers.UserDisplayName: user324810
Body: <p>I can't cope with reworking the result. If id is the same I want to stick those items.</p>
  <pre><code>with open(x,'r') as rf:
      l = fr.readlines()
      previous_line_id = ''
      corrected_lines = []
  
      for i in l:
         i_split = i.split('\t')
         id_ = i_split[0]
         if id_ == previous_line
             xxxxxxxxxx
         else:
             corrected_lines .append(i)
  </code></pre>
  <p>result:</p>
  <pre><code>    WP_XXXXXXXX2.1  PF06325 Ribosomal protein L11 methyltransferase (PrmA)  5
      WP_192XXXXXX.1  PF13489 Methyltransferase domain    4
      XXXXXXX45.1 PF02310 B12 binding domain  12  &lt;-----------  DOUBLE IDS
      XXXXXXX45.1 PF04055 Radical SAM superfamily 5 &lt;-----------
      WP_XXXXXXX29.1  PF13489 Methyltransferase domain    4
      WP_0XXXXXXXX.1  PF13489 Methyltransferase domain    4
      WP_XXXXXXX90.1  PF06325 Ribosomal protein L11 methyltransferase (PrmA)  5  &lt;--------------   DOUBLE ID
      WP_XXXXXXX90.1  PF06325 Ribosomal protein L11 methyltransferase (PrmA)  7  &lt;--------------
      WP_0XXXXXX62.1  PF13489 Methyltransferase domain    4
  </code></pre>
  <p>result I need:</p>
  <pre><code>WP_XXXXXXXX2.1  PF06325 Ribosomal protein L11 methyltransferase (PrmA)  5
  WP_192XXXXXX.1  PF13489 Methyltransferase domain    4
  XXXXXXX45.1 PF02310 B12 binding domain  12; PF04055 Radical SAM superfamily 5 &lt;----------- STICKED SAME ID,OTHER VALUES
  WP_XXXXXXX29.1  PF13489 Methyltransferase domain    4
  WP_0XXXXXXXX.1  PF13489 Methyltransferase domain    4
  WP_XXXXXXX90.1  PF06325 Ribosomal protein L11 methyltransferase (PrmA)  5; PF06325  Ribosomal protein L11 methyltransferase (PrmA)  7  &lt;--------- STICKED STICKED SAME ID,OTHER VALUES
  WP_0XXXXXX62.1  PF13489 Methyltransferase domain    4
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-25T19:53:19.753Z
Comments.Text: I am sorry, but I don't understand what you want exactly. Could you please elaborate on what you are trying to achieve ?
Comments.UserDisplayName: user324810
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-25T20:08:15.903Z
Comments.Text: @user324810 I commented text
Comments.UserDisplayName: MTG
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-25T20:12:37.653Z
Comments.Text: @user324810 I want to remove the double id and merge their values together
Comments.UserDisplayName: MTG
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-25T20:18:37.500Z
Comments.Text: Thank you. Give me a moment
Comments.UserDisplayName: user324810
Tags: <python>
Title: connect same ids with values in id rows (result of effectiveELD)
ThreadText: # connect same ids with values in id rows (result of effectiveELD)
  
  (Asked by: username_0 on 2022-01-25)
  
  I can't cope with reworking the result. If id is the same I want to stick those items.
  
  ```
  with open(x,'r') as rf:
      l = fr.readlines()
      previous_line_id = ''
      corrected_lines = []
  
      for i in l:
         i_split = i.split('\t')
         id_ = i_split[0]
         if id_ == previous_line
             xxxxxxxxxx
         else:
             corrected_lines .append(i)
  
  ```
  
  result:
  
  ```
      WP_XXXXXXXX2.1  PF06325 Ribosomal protein L11 methyltransferase (PrmA)  5
      WP_192XXXXXX.1  PF13489 Methyltransferase domain    4
      XXXXXXX45.1 PF02310 B12 binding domain  12  <-----------  DOUBLE IDS
      XXXXXXX45.1 PF04055 Radical SAM superfamily 5 <-----------
      WP_XXXXXXX29.1  PF13489 Methyltransferase domain    4
      WP_0XXXXXXXX.1  PF13489 Methyltransferase domain    4
      WP_XXXXXXX90.1  PF06325 Ribosomal protein L11 methyltransferase (PrmA)  5  <--------------   DOUBLE ID
      WP_XXXXXXX90.1  PF06325 Ribosomal protein L11 methyltransferase (PrmA)  7  <--------------
      WP_0XXXXXX62.1  PF13489 Methyltransferase domain    4
  
  ```
  
  result I need:
  
  ```
  WP_XXXXXXXX2.1  PF06325 Ribosomal protein L11 methyltransferase (PrmA)  5
  WP_192XXXXXX.1  PF13489 Methyltransferase domain    4
  XXXXXXX45.1 PF02310 B12 binding domain  12; PF04055 Radical SAM superfamily 5 <----------- STICKED SAME ID,OTHER VALUES
  WP_XXXXXXX29.1  PF13489 Methyltransferase domain    4
  WP_0XXXXXXXX.1  PF13489 Methyltransferase domain    4
  WP_XXXXXXX90.1  PF06325 Ribosomal protein L11 methyltransferase (PrmA)  5; PF06325  Ribosomal protein L11 methyltransferase (PrmA)  7  <--------- STICKED STICKED SAME ID,OTHER VALUES
  WP_0XXXXXX62.1  PF13489 Methyltransferase domain    4
  
  ```
  
  **Tags:** python
  
  > **Comments:**
  > **username_1**: I am sorry, but I don't understand what you want exactly. Could you please elaborate on what you are trying to achieve ?  
  > **username_0**: @username_1 I commented text  
  > **username_0**: @username_1 I want to remove the double id and merge their values together  
  > **username_1**: Thank you. Give me a moment  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-01-25. Score: 2 | Accepted answer
  
  Assuming that the file `test.txt` is tab-separated values with these fields:
  
  ```
  WP_XXXXXXXX2.1  PF06325     Ribosomal protein L11 methyltransferase (PrmA)      5
  WP_192XXXXXX.1  PF13489     Methyltransferase domain                            4
  XXXXXXX45.1     PF02310     B12 binding domain                                  12 
  XXXXXXX45.1     PF04055     Radical SAM superfamily                             5
  WP_XXXXXXX29.1  PF13489     Methyltransferase domain                            4
  WP_0XXXXXXXX.1  PF13489     Methyltransferase domain                            4
  WP_XXXXXXX90.1  PF06325     Ribosomal protein L11 methyltransferase (PrmA)      5
  WP_XXXXXXX90.1  PF06325     Ribosomal protein L11 methyltransferase (PrmA)      7
  WP_0XXXXXX62.1  PF13489     Methyltransferase domain                            4
  
  ```
  
  You can proceed first by reading your file:
  
  ```
  with open("test.txt",'r') as rf:
      l = rf.readlines() # all the lines are stored in variable 'l'
  
  ```
  
  You should create a dictionary with your ID as keys and the remaining line as values:
  
  ```
  # create empty dictionary
  dict_id = {}
  
  for i in l:                                                               # for each line
      key_id = i.split("\t")[0]                                             # get the id
      if key_id not in dict_id.keys():                                      # if id as key is not found in dictionary
          value = "\t".join(i.split("\t")[1:]).rstrip()                     # parse the value
          dict_id[key_id] = [value]                                         # add the id as key to dictionary with its value
      else:                                                                 # else if id as key is already in dictionary
          dict_id[key_id].append("\t".join(i.split("\t")[1:]).rstrip())     # append to id as key
  
  ```
  
  And now, you can print the result:
  
  ```
  for key, value in dict_id.items():         # for each key, values in dictionary
      print(key + ": " + "; ".join(value))   # print the key and their values separated by '; '
  
  ```
  
  And you should obtain:
  
  ```
  WP_XXXXXXXX2.1: PF06325 Ribosomal protein L11 methyltransferase (PrmA)  5
  WP_192XXXXXX.1: PF13489 Methyltransferase domain        4
  XXXXXXX45.1: PF02310    B12 binding domain      12; PF04055     Radical SAM superfamily 5
  WP_XXXXXXX29.1: PF13489 Methyltransferase domain        4
  WP_0XXXXXXXX.1: PF13489 Methyltransferase domain        4
  WP_XXXXXXX90.1: PF06325 Ribosomal protein L11 methyltransferase (PrmA)  5; PF06325      Ribosomal protein L11 methyltransferase (PrmA)  7
  WP_0XXXXXX62.1: PF13489 Methyltransferase domain        4
  
  ```
  
  The final script:
  
  ```
  with open("test.txt",'r') as rf:
      l = rf.readlines()
  
  dict_id = {}
  for i in l:
      key_id = i.split("\t")[0]
      if key_id not in dict_id.keys():
          value = "\t".join(i.split("\t")[1:]).rstrip()
          dict_id[key_id] = [value] 
      else:
          dict_id[key_id].append("\t".join(i.split("\t")[1:]).rstrip())
  
  for key, value in dict_id.items():
      print(key + ": " + "; ".join(value))
  
  ```
  
  > **Comments:**
  > **username_0**: realy thanks :) all best  
  
  ---
  
  