TUPLES : là một tập hợp bất biến của các giá trị riêng biệt của các kiểu dữ liệu giống nhau hoặc khác nhau được phân tách bằng dấu phẩy.
Cú pháp: (item1, item2, item3…)
Từ điển: là một tập hợp các cặp khóa-giá trị, trong đó mỗi giá trị trong từ điển có thể được truy cập bằng khóa của nó. Các cặp khóa-giá trị này không cần cùng kiểu dữ liệu.
Cú pháp: Dict (key1 => value1, key2 => value2,…)
#create an empty tuple
t1=()
println(“If a Tuple is empty returns “, isempty(t1))
t1=(“julia”,”python”,”sql”)
println(“If a Tuple is non-empty returns “,isempty(t1))
Output:
If a Tuple is empty returns true
If a Tuple is non-empty returns false
#declare a tuple beverage
beverage= (“coffee”,”tea”,”greentea”,”grrencoffee”,”ginger tea”)
#Indexing
println(beverage[1])
Output: coffee
println(beverage[0]) #index in julia starts from 1
BoundsError: attempt to access NTuple{5, String} at index [0]
Stacktrace:
[1] getindex(t::Tuple, i::Int64)
@ Base .\tuple.jl:29
[2] top-level scope
@ In[7]:2
[3] eval
@ .\boot.jl:373 [inlined]
[4] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base .\loading.jl:1196
#Slicing
println(beverage[2:4])
Output:
("tea", "greentea", "grrencoffee")
#Iteration
println("iterating over tuple :")
for i in beverage
println(i)
end
Output:
iterating over tuple :
coffee
tea
greentea
grrencoffee
ginger tea
#Tuple manipulation:
beverage[3]="chamomile tea"
Output:
MethodError: no method matching setindex!(::NTuple{4, String}, ::String, ::Int64)
Stacktrace:
[1] top-level scope
@ In[7]:2
[2] eval
@ .\boot.jl:373 [inlined]
[3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base .\loading.jl:1196
Phương thức Tuple ()
#reverse a tuple
rev= reverse(beverage)
println(rev)
Output:("ginger tea", "grrencoffee", "greentea", "tea", "coffee")
#length of tuple
println(“length of tuple “,length(beverage))
Output: length of tuple 5
#check if empty or not
println(isempty(beverage))
Output: false
lang= (l1=”julia”,l2=”python”,l3=”SQL”)
println(lang)
Output: (l1 = "julia", l2 = "python", l3 = "SQL")
println(lang[2])
Output: python
println(lang.l1)
Output: julia
#create a dictionary
empIDs= Dict(“vivek”=>121,”aniket”=>134,”jagdish”=>101)
println(typeof(empIDs))
println(empIDs)
Output:
Dict{String, Int64}
Dict("jagdish" => 101, "vivek" => 121, "aniket" => 134)
#create dict from tuple
eds=[("vivek",2000),("jagdish",5000),("aniket",3500)]
println(typeof(eds))
println(eds)
Output:
Vector{Tuple{String, Int64}}
[("vivek", 2000), ("jagdish", 5000), ("aniket", 3500)]
#conver the tuple into dictionary
edict=Dict(eds)
println(typeof(edict))
println(edict)
Output:
Dict{String, Int64}
Dict("jagdish" => 5000, "vivek" => 2000, "aniket" => 3500)
println(edict)
Output:
Dict("jagdish" => 5000, "vivek" => 2000, "aniket" => 3500)
key=keys(edict)
println(“keys are :”,key)
Output: keys are :["jagdish", "vivek", "aniket"]
val=values(edict)
println(“values are :”, val)
Output: values are :[5000, 2000, 3500]
#Iterate over dictionary using for loop
for (key,val) in edict
println(key,"=>",val)
end
Output:
jagdish=>5000
vivek=>2000
aniket=>3500
get () và getkey ()
#get() method: Return the value stored for the given key
#syntax: get(collection, key, default)
println(edict)
Output:
Dict("jagdish" => 5000, "vivek" => 2000, "aniket" => 3500)
println(get(edict,"vivek",-1))
Output: 2000
#default value is mandatory otherwise it throws error
println("Key not found ",get(edict,"viv",0))
Output: Key not found 0
#wihtout default value
println("Key not found ",get(edict,"viv"))
Output:
MethodError: no method matching get(::Dict{String, Int64}, ::String)
Closest candidates are:
get(::Dict{K, V}, ::Any, ::Any) where {K, V} at C:\Users\lenovo\AppData\Local\Programs\Julia-1.7.1\share\julia\base\dict.jl:506
get(::IJulia.IJuliaStdio, ::Any, ::Any) at C:\Users\lenovo\.julia\packages\IJulia\e8kqU\src\stdio.jl:21
get(::Test.GenericDict, ::Any, ::Any) at C:\Users\lenovo\AppData\Local\Programs\Julia-1.7.1\share\julia\stdlib\v1.7\Test\src\Test.jl:1800
...
Stacktrace:
[1] top-level scope
@ In[57]:7
[2] eval
@ .\boot.jl:373 [inlined]
[3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base .\loading.jl:1196
#getkey()
Return the key matching argument key if one exists in collection, otherwise return default.
println(getkey(edict,"aniket",-1))
Output: aniket
println(getkey(edict,"viv",-1))
Output: -1
println(edict)
Output:
Dict("jagdish" => 5000, "vivek" => 2000, "aniket" => 3500)
delete!(edict,”vivek”)
println(edict)
Output:
Dict("jagdish" => 5000, "aniket" => 3500)
#delete a non-existing item
delete!(edict,"viv")
Output:
Dict{String, Int64} with 2 entries:
"jagdish" => 5000
"aniket" => 3500
#merge dictionaries using merge()
d1 = Dict(“a”=>1, “b”=>9, “c”=>3)
d2 = Dict(“e”=>7, “f”=>2, “h”=>5)
println(merge(d1,d2))
Output:
Dict("f" => 2, "c" => 3, "e" => 7, "b" => 9, "a" => 1, "h" => 5)
#common keys present
d1 = Dict("a"=>1, "b"=>9, "c"=>3)
d2 = Dict("e"=>7, "b"=>2, "h"=>5)
println(merge(d1,d2))
Output:
Dict("c" => 3, "e" => 7, "b" => 2, "a" => 1, "h" => 5)
#merge dictionaries using mergewith()
d1 = Dict("a"=>1, "b"=>9, "c"=>3)
d2 = Dict("e"=>7, "b"=>2, "h"=>5)
println(mergewith!(+,d1,d2))
Output:
Dict("c" => 3, "e" => 7, "b" => 11, "a" => 1, "h" => 5)
#add new item to a dict
println(edict)
Output: Dict("jagdish" => 5000, "aniket" => 3500)
edict[“vivek”]=2700
println(edict)
Output: Dict("jagdish" => 5000, "vivek" => 2700, "aniket" => 3500)
#change dict vaue for a key
println(edict)
Output: Dict("jagdish" => 5000, "vivek" => 2700, "aniket" => 3500)
edict["vivek"]=4000
println(edict)
Output: Dict("jagdish" => 5000, "vivek" => 4000, "aniket" => 3500)
Tiếp tục hỗ trợ.
Trong thế giới có nhịp độ nhanh và cạnh tranh ngày nay, sự nghiệp của một người đóng một vai trò quan trọng trong sự phát triển cá nhân, ổn định tài chính và sự hài lòng trong cuộc sống nói chung. Tuy nhiên, nhiều cá nhân thấy mình bị mắc kẹt trong một chu kỳ trì trệ và không hài lòng không ngừng, dần dần lãng phí trong cuộc sống nghề nghiệp của họ.
Chúng ta thường thấy mình phải vật lộn để thực hiện những gì chúng ta biết là tốt cho chúng ta. Từ việc nói với một người quan trọng khác rằng chúng ta yêu họ đến việc nhớ nói chuyện như một tên cướp biển, sẽ luôn có những người cho rằng không cần thiết phải tổ chức các sự kiện trong ngày, tuần hoặc tháng vì họ đã làm những việc đó rồi.
Bạn có thể là Điều tra viên OSINT, Người chơi CTF hoặc đơn giản là người nhận được các cuộc gọi spam. Ai đó đang cố xác minh số bạn đã thấy trong quảng cáo.
Giới thiệu: Chào mừng những độc giả dũng cảm đến với cuộc hành trình sẽ đưa chúng ta đến những nơi sâu thẳm nhất của hành tinh chúng ta. Trong blog này, chúng tôi đi sâu vào thế giới bí ẩn của Rãnh Mariana, khám phá những bí mật ẩn giấu của nó và khám phá những sự thật lạnh thấu xương nằm bên dưới bề mặt của nó.
Tay tôi ngứa ngáy lan rộng khi tôi mặc cả với người bán sách địa phương để mua một cuốn sách khác. Cuốn sách này giống như những cuốn còn lại mà tôi đã mua gần đây sẽ lên ngôi trong đống 'Cần đọc' (TBR) của tôi; tuy nhiên, tôi đã mua nó.
Khi bạn gửi yêu cầu tới facebook.com, máy tính của bạn sẽ tra cứu tên miền để dịch tên miền đó thành địa chỉ IP để máy tính của bạn có thể thực hiện kết nối đó.