For something that common, chances are there is a dupe for both. So if there is an exact dupe, use it. TBH, I feel it is a bit of a judgment call, honestly. But that is of course subjective. Here's what I tend to go by (this is my opinion).
In your specific example, I'd flag as a dupe of this question (if the OP was using Python). The question is asking for a substring
method, and one answer explains the in
keyword ("hello" in "hello world"
) while another demonstrates it with a not
(not
is the Python version of !
("hi" not in "hello world"
). So sometimes the dupe might still have an answer that answers it, even if the first one doesn't! So that may work.
If there isn't an answer that explains exactly what they're asking, I'd be more wary about dupe flagging. Imagine, for example, someone posts a question saying "In Java, how can I see if the file ~/hello.txt
exists so I can create it if it doesn't already exist"
You might be tempted to have it be a dupe of this question. But no, it shouldn't be! Because if the OP then might write code like this:
File f = new File(filePathString);
if(!f.exists() && !f.isDirectory()) {
// create the file
}
Unfortunately, that is wrong, as if some other program creates it after the if
but before the Java code makes the file, the OP will have an issue. Instead, they should just try to create it and catch
the exception if it exists.
Ideally, there is an actual dupe. But if it would really be as simple as saying "not
something", I'd mark as a dupe. But please don't do that unless you are sure there aren't any hidden pitfalls with doing that.
!
) there are likely duplicates for both scenarios already.