Jan-09-2023, 05:25 PM
As odd as this may sound, it is faster to compare sets BECAUSE they are unordered. Because sets are unordered, they can be optimized to access items by value (actually their hash value) instead of index. Kind of liked a lean dictionary without the value mapping. It is much faster to test that "u" is in set(alpha) than alpha.
You cannot use sets to compare collections when order is important. Obviously panagram != alpha, but they do have the same letters so set(alpha) == set(panagram).
You cannot use sets to compare collections when order is important. Obviously panagram != alpha, but they do have the same letters so set(alpha) == set(panagram).