How to get vector of tuples from the vector of tuples using certain conditions?

I have a vector containing tuples and I want to extract some tuples that meet certain conditions. I tried something as shown below but didn’t get the expected result.

A = [(1,2),(3,2),(3,4),(5,4),(3,2)]
A_c = findall(x->x[2] <= 2, A)
# I get A_c = [1,2,5], but I need A_c = [(1,2),(3,2),(3,2)]

Your help will be highly appreciated.

julia> A[A_c]
3-element Vector{Tuple{Int64, Int64}}:
 (1, 2)
 (3, 2)
 (3, 2)
1 Like
julia> [a for a in A if a[2]<=2]
3-element Vector{Tuple{Int64, Int64}}:
 (1, 2)
 (3, 2)
 (3, 2)

julia> filter(x->x[2]<=2, A)
3-element Vector{Tuple{Int64, Int64}}:
 (1, 2)
 (3, 2)
 (3, 2)
3 Likes