Problem:
- Trying to evaluate first 4 characters of each item in list.
- If the first 4 chars match another first 4 chars in the list, then append the last three digits to the first four. See example below.
Notes:
- The list values are not hard coded.
- The list always has this structure “####.###”.
- Only need to match first 4 chars in each item of list.
- Order is not essential.
Code:
Grid = ["094G.016", "094G.019", "194P.005", "194P.015", "093T.021", "093T.102", "094G.032"]
Desired Output:
Grid = ["094G.016\019\032", "194P.005\015", "093T.021\102"]
Research:
-
I know that sets can find duplicates, could I use a set to evaluate only the 1st 4 chars, would I run into a problem since indexing of sets cannot be done?
-
Would it be better to split the list items into the 2 parts. The four digits before the period (“094G”), and a separate list of the three digits after the period (“093”), compare them, then join them in a new list?
-
Is there a better way of doing this all together that I’m not realizing?
Here is one straightforward way to do it.
Gives unordered
result: