I want to remove words from a dictionary given certain conditions. I would like to do so that in the next iteration the dictionary will calculate over the new one, that has that last item removed, so it won't calculate again.
// sample data
$dict = ['aaa', 'aaan','aba', 'abat', 'ime', 'iso', 'nime', 'tiso',];
$unique = ['abatiso', 'aaanime'];
// could use while to further optimize unset (and remove on the fly) http://php.net/manual/en/control-structures.foreach.php#88578
while (list($key_word, $word) = each($unique)) { // $key is unused, just for the optimization that the whille provides
foreach ($dict as $key_other => $other) {
// ... conditions calculations
unset($unique[$key_word]);
}
}
echo "n compounds: " . count($compounds) . NL;
If I set the inner loop with a while instead foreach as the outer, I get 0 results, it terminates inmediately.
For now, I'm getting duplicate results like:
// Removed: abatiso => wc: aba + tiso = abatiso // Removed: abatiso => wc: abat + iso = abatiso // Removed: abatiso => wc: abati + so = abatiso // Removed: abatiso => wc: abatis + o = abatiso
How can I make it so it removes the word and won't proccess it again on next iteration?
Some test data:
Removed: aaaaaah => wc: aaaa + aah = aaaaaah
Removed: aaaaaah => wc: aaaaaa + h = aaaaaah
Removed: aaaaargh => wc: aaa + aargh = aaaaargh
Removed: aaaalead => wc: aaaa + lead = aaaalead
Removed: aaabbbccc => wc: aaab + bbccc = aaabbbccc
Removed: aaacomix => wc: aaa + comix = aaacomix
Removed: aaagak => wc: aaa + gak = aaagak
Removed: aaahh => wc: aaa + hh = aaahh
Removed: aaainc => wc: aaa + inc = aaainc
Removed: aaainc => wc: aaai + nc = aaainc
Removed: aaanet => wc: aaa + net = aaanet
Removed: aaanet => wc: aaan + et = aaanet
Removed: aaanime => wc: aaa + nime = aaanime
Removed: aaanime => wc: aaan + ime = aaanime
Removed: aaaron => wc: aaa + ron = aaaron
Removed: aabbcc => wc: aab + bcc = aabbcc
Removed: aabmup => wc: aab + mup = aabmup
Removed: aabre => wc: aab + re = aabre
Removed: aabybro => wc: aaby + bro = aabybro
Removed: aacap => wc: aac + ap = aacap
Removed: aacap => wc: aaca + p = aacap
Removed: aaccording => wc: aac + cording = aaccording
Removed: aacd => wc: aac + d = aacd
Removed: aachener => wc: aach + ener = aachener
Removed: aachener => wc: aachen + er = aachener
Removed: aacisuan => wc: aaci + suan = aacisuan
Removed: aacisuan => wc: aacis + uan = aacisuan
Removed: aacult => wc: aac + ult = aacult
I'm not using a break inside the inner loop because I have to do calculations also.