Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use the <code>index()</code> function to find your dashes, then with that knowledge you can take the rest of the string past that point. For instance, </p> <pre><code>mydict = {"g18_84pp_2A_MVP1_GoodiesT0-HKJ-DFG_MIX-CMVP1_Y1000-MIX.txt" : 0, "g18_84pp_2A_MVP2_GoodiesT0-HKJ-DFG_MIX-CMVP2_Y1000-MIX.txt" : 1, "g18_84pp_2A_MVP3_GoodiesT0-HKJ-DFG_MIX-CMVP3_Y1000-MIX.txt" : 2, "g18_84pp_2A_MVP4_GoodiesT0-HKJ-DFG_MIX-CMVP4_Y1000-MIX.txt" : 3, "g18_84pp_2A_MVP5_GoodiesT0-HKJ-DFG_MIX-CMVP5_Y1000-MIX.txt" : 4, "g18_84pp_2A_MVP6_GoodiesT0-HKJ-DFG_MIX-CMVP6_Y1000-MIX.txt" : 5, "g18_84pp_2A_MVP7_GoodiesT0-HKJ-DFG_MIX-CMVP7_Y1000-MIX.txt" : 6, "h18_84pp_3A_MVP1_GoodiesT1-HKJ-DFG_MIX-CMVP1_Y1000-FIX.txt" : 7, "h18_84pp_3A_MVP2_GoodiesT1-HKJ-DFG_MIX-CMVP2_Y1000-FIX.txt" : 8, "h18_84pp_3A_MVP2_GoodiesT1-HKJ-DFG_MIX-CMVP3_Y1000-FIX.txt" : 9} for value in sorted(mydict.iterkeys()): index = value.index('-') extracted = value[index+1:-4] # Goes past the first occurrence of - and removes .txt from the end print extracted[-3:] # Find the last 3 letters in the string </code></pre> <p>Will print the following:</p> <pre><code>MIX MIX MIX MIX MIX MIX MIX FIX FIX FIX </code></pre> <p>Then if statements can be used to do what you would like.</p> <p>If you want to extract just the common part.</p> <pre><code>index = value.index('-') extracted = value[:index] # Will get g18_84pp_2A_MVP1_GoodiesT0 </code></pre> <p>Then to figure out the ending to use. If you know the ending of the mydict value will always be MIX.txt or FIX.txt then you can do this.</p> <pre><code>for value in sorted(mydict.iterkeys()): ending = value[-7:-4] index = value.index('-') extracted = value[:index] print "%s_%s" % (extracted, ending) </code></pre> <p>Which prints </p> <pre><code>g18_84pp_2A_MVP1_GoodiesT0_MIX g18_84pp_2A_MVP2_GoodiesT0_MIX g18_84pp_2A_MVP3_GoodiesT0_MIX g18_84pp_2A_MVP4_GoodiesT0_MIX g18_84pp_2A_MVP5_GoodiesT0_MIX g18_84pp_2A_MVP6_GoodiesT0_MIX g18_84pp_2A_MVP7_GoodiesT0_MIX h18_84pp_3A_MVP1_GoodiesT1_FIX h18_84pp_3A_MVP2_GoodiesT1_FIX h18_84pp_3A_MVP2_GoodiesT1_FIX </code></pre> <p>Then you add it to the extracted dictionary.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload