I have a list of strings, here’s an example:
wallList = ['wall_l0', 'wall_l1', 'wall_broken_l0', 'wall_broken_l1',
'wall_vwh_l0','wall_vwh_l1', 'wall_vwh_broken_l0',
'wall_vwh_broken_l1', 'wall_vpi_l0', 'wall_vpi_l1',
'wall_vpi_broken_l0', 'wall_vpi_broken_l1']
And I’d like to group them together by wall type, and state (default / broken):
[['wall_l0', 'wall_l1'],['wall_broken_l0', 'wall_broken_l1']]
[['wall_vwh_l0', 'wall_vwh_l1'],['wall_vwh_broken_l0', 'wall_vwh_broken_l1']]
[['wall_vpi_l0', 'wall_vpi_l1'],['wall_vpi_broken_l0', 'wall_vpi_broken_l1']]
Anyone know how best to do this, or know of a python recipe?
Interesting, first we need to break it up by wall type so we can do this.
great now that we have the types lets separate by those that are broken.
this is what everything looks like together.
there are surely other ways, but this seems to be concise.
Here is another way:
This second method should be faster since we are only iterating once, dictionary look ups are constant, and we can access any set of walls by name as well as state …