Search a list of records: Difference between revisions

(Adding Julia)
Line 770:
 
=={{header|Julia}}==
<lang Julia>dataset = [Dict([( "name" , "Lagos"), ("population", 21.0 )]),
Dict([( "name" , "Cairo"), ("population", 15.2 )]),
Dict([( "name" , "Kinshasa-Brazzaville"), ("population", 11.3 )]),
Dict([( "name" , "Greater Johannesburg"), ("population", 7.55 )]),
Dict([( "name" , "Mogadishu"), ("population", 5.85 )]),
Dict([( "name" , "Khartoum-Omdurman"), ("population", 4.98 )]),
Dict([( "name" , "Dar Es Salaam"), ("population", 4.7 )]),
Dict([( "name" , "Alexandria"), ("population", 4.58 )]),
Dict([( "name" , "Abidjan"), ("population", 4.4 )]),
Dict([( "name" , "Casablanca"), ("population", 3.98 )])]
 
println("Find the (one-based) index of the first city in the list whose name is \"Dar Es Salaam\" (note: Julia is not zero-based)")
println(find(x -> x["name"] == "Dar Es Salaam", dataset)[1])
println()
println("Find the name of the first city in this list whose population is less than 5 million")
println(filter(x -> x["population"] < 5, dataset)[1]["name"])
println()
println("Find the population of the first city in this list whose name starts with the letter \"A\"")
println(filter(x -> x["name"][1] == 'A', dataset)[1]["population"])
</lang>
 
=={{header|Lingo}}==
Anonymous user