Note that there are some explanatory texts on larger screens.

plurals
  1. POGroup similar items in a master list and create new lists based on grouped items
    primarykey
    data
    text
    <p>I am trying to create several new lists from one master list whereby the new lists contain similar items from the master list. Specifically, I have a list of bus routes. Here is a sample data set:</p> <pre><code>[u'Bus04_00_00_IB_pts_Line', u'Bus04_00_00_OB_pts_Line', u'Bus15_00_00_IB_pts_Line', u'Bus15_00_00_OB_pts_Line'] </code></pre> <p>Most bus routes have an inbound (IB) and an outbound (OB) item, (and some have multiple IBs and OBs, and some have only one route, b/c they are loop routes). Eventually, I want to merge the IB and OB routes in mapping software (which I already know how to do)...</p> <p>I originally created the filenames so that the first 5 characters represent the bus route, whether or not it's IB or OB. Therefore, I am able to group similar items based on the first 5 characters. For example, when I write:</p> <pre><code>for route in routes: print route[0:5] </code></pre> <p>I get:</p> <pre><code>&gt;&gt;&gt; Bus04 Bus04 Bus15 Bus15 </code></pre> <p>How can I "group" the files that pertain to <code>Bus04</code> and <code>Bus04</code>, and <code>Bus15</code> and <code>Bus15</code> into new lists, such that I get:</p> <p><code>[u'Bus04_00_00_IB_pts_Line', u'Bus04_00_00_OB_pts_Line']</code> and <code>[u'Bus15_00_00_IB_pts_Line', u'Bus15_00_00_OB_pts_Line']</code> as separate lists?</p> <p>I am thinking something along the lines of looping through each item, looking at the first five characters of each, then either create a new list with each new five character item that comes up (and add that item to the new list) or checking whether a list already exists and appending the similar item to it. </p> <p>I'm having a hard time writing this out in code, so any help is greatly appreciated!</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.
 

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