Quantcast
Channel: Active questions tagged string-manipulation - Mathematica Stack Exchange
Viewing all articles
Browse latest Browse all 186

Delete all strings that are prefixes of another string

$
0
0

I have a long list of strings and I'm trying to find a more efficient way of removing those elements that are prefixes of another:

example = {"Clothing", "Clothing/Accessories", "Clothing/Accessories/Belts", "Watches", "Watches/Accessories", "Watches/Accessories/Pocket Watch Chains"}

This is what I have, but it is not very optimized:

DeleteCases[example, a_ /; Or @@ Table[     StringStartsQ[b, a], {b, DeleteCases[example, a]}]]
 {"Clothing/Accessories/Belts", "Watches/Accessories/Pocket Watch Chains"} 

My real example has 13,732 strings and it takes 292.156 seconds to pare it down to 11,372.


Viewing all articles
Browse latest Browse all 186

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>