-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
findin does not work for strings? #11630
Comments
This is my interpretation from looking at the documentation:
julia> findin(l, "a")
0-element Array{Int64,1}
julia> findin(l, ["a"])
2-element Array{Int64,1}:
1
2 |
I see. Thanks @KristofferC , I think I misuse it. But it does return the correct result for integers. julia> findin([1,2,3,3,4], 3)
2-element Array{Int64,1}:
3
4 |
Ok so this is the definition of function findin(a, b)
ind = Array(Int, 0)
bset = Set(b)
@inbounds for i = 1:length(a)
a[i] in bset && push!(ind, i)
end
ind
end The problem is that for a string julia> Set("a")
Set(['a'])
julia> typeof(Set("a"))
Set{Char} and thus later in the function this fails: julia> "a" in Set("a")
false On the other hand, these are true julia> "a" in Set(["a"])
true
julia> 'a' in Set(["a"])
true I am a bit surprised that Maybe you should reopen this to confirm that this is what is expected. |
If you want to look for strings in a string (as opposed to |
@nalimilan: "If String wasn't a collection but a scalar, you would get an error." This doesn't seem to be the case. julia> findin([1,2,3,3,4], 3)
2-element Array{Int64,1}:
3
4 Because set of a scalar promotes it to a container with the scalar as the only item? |
No, that's because numbers are considered as collections at the moment: julia> 2[1]
2 I find it a bit confusing, for people have advocated that it was often useful. |
Oh, I see. Thanks. |
Thanks @nalimilan and @KristofferC for clarifying this. |
I am using Julia Version 0.4.0-dev+5149 (2015-06-01 18:58 UTC).
Suppose I have a list
l
then
findfirst
andfindlast
can find the correct index.But
findin(l, "a")
returns nothingIs this a bug or I misunderstand something?
Thanks,
Weijian
The text was updated successfully, but these errors were encountered: