Can someone help me with this? It seems like it should be easy but I can’t quite figure it out.
I’m trying to find all of the array indicies in this String array that matches the search string
Something like the following
data = ["abc","bcd","def","GHF"]
findall( x -> x == "b", data)
I was hoping to get that this string is found in the array at indexes 1,2 but it returns nothing. Is there some syntax that I’m not getting right here?
I’m sure there is some logical reason, but anyone know why with occursin() the search term is the first argument and with startswith(), the search term is the second argument? Doesn’t that make it hard to remember?
Well, the documentation cannot address every possible use case. But you can reason about your code, and think about what it’s doing, because the behavior you saw does make sense.
For every element in data it checks, is “abc” equal to “b”, is “bcd” equal to “b”, etc. And of course the answer each time is ‘no’.
Yes, I agree that in retrospect, that makes sense and I should have been able to figure it out, but just using logic or intuition hasn’t been that useful to figure out the syntax in Julia because if I were to do that, I think the following would make way more sense
findall( "b", occursin(data))
or more simply
occursin("b", data)
rather than
findall( x -> occursion("b", x), data)
But, either way, it’s still better than Python so I’ll keep trying
Well, I respectfully disagree I don’t think these make sense at all. The first one is unclear, but the second obviously checks if "b" is one of the elements of data, which it isn’t. I mean, what else could it mean?
occursin surely has to to work on each element ofdata, not on the data as a whole.