Hi,
I think the expected output has two repeated strings: “aat” and “att”. This makes the tester expect a 78 size list. Shouldn’t this be a 76 size list (if we remove these two repeated elements) ?
Thanks !
Francisco
Hi,
I think the expected output has two repeated strings: “aat” and “att”. This makes the tester expect a 78 size list. Shouldn’t this be a 76 size list (if we remove these two repeated elements) ?
Thanks !
Francisco
That is a good point. But the course creators chose this (list()
) approach probably for students to be more friendly. They could have used set()
and that would have been a valid choice too.
The reason that is not a problem because in later functions we use set()
to remove the duplicates, most importantly - across the “delete”, “insert” etc. possible combinations. And we would have had to use this operation (set
) even if we removed the duplicates prior.
Cheers!
You already suggest using a set at # UNQ_C6 GRADED FUNCTION: in
def replace_letter. Please your comment below. Why the sudden change of heart? A set is cleaner.
Thank you for your response.
I have already passed this test. But I am still left wondering why not a “set” as opposed to a “list.”
You may have duplicate words in a list. Before you say it is too hard for beginners, you have already suggested making a “set” out of a “list” in a previous problem.
A set can also be sorted.
If I remember correctly it was not the case up to some Python version (I believe Python 3.7) and the function sorted()
first turns a set into a list anyway… In principal, the sets {1, 2}
and {2, 1}
are the same set and how programming languages “deal” with them is ever changing and not consistent.
In principal, lists have to have order and sets should not. (or in other words, [2, 1] and [1, 2] are not the same, while {2, 1} and {1, 2} should be the same).
Cheers
Interesting point. I was not aware of that. Thank you!
I guess one can always change a set to a list, sort it and change it back to a set in order to have reproducible results.
Regards & Cheers!