TUPLES : 쉼표로 구분된 동일하거나 다른 데이터 유형의 고유한 값을 변경할 수 없는 모음입니다.
구문: (항목1, 항목2, 항목3…)
사전: 사전 의 각 값에 해당 키로 액세스할 수 있는 키-값 쌍의 모음입니다. 이러한 키-값 쌍은 동일한 데이터 유형일 필요가 없습니다.
구문: Dict(키1 => 값1, 키2 => 값2, …)
#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
튜플 메서드()
#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() 및 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)
계속 지원하십시오.
Alyson Lee, 공무 관리 고문 연방 정부의 연간 예산 책정 과정은 이산화탄소 제거(CDR) 기금 마련을 위한 노력의 핵심입니다. 매년 Carbon180은 내년의 자금 흐름을 안내하기 위해 다양한 의회 사무소에 요청을 제출합니다.
페트병, 유리병, 알루미늄캔, 그린에너지 패키지를 무심코 버린 적이 몇 번이나 되셨나요? 재활용에 대한 대가로 무언가를 얻을 수 있기를 몇 번이나 바랐습니까? 당신이 대부분의 사람들과 같다면 대답은 아마도 여러 번일 것입니다. 재활용은 종종 번거로움, 자질구레한 일 또는 즉각적이거나 실질적인 혜택을 가져오지 않는 의무로 간주됩니다.
이성적인 마음을 가진 사람이라면 정치계와 언론계가 좌파, 심지어 극좌파에 의해 지배되고 있다는 사실을 알고 있습니다. 종교 분야에서 이러한 불균형은 분명히 눈에 띕니다. 좌익 신문과 네트워크는 기독교 신앙을 옹호하기 위해 서두르지 않습니다.
2022년에는 GPT-3가 출시되면서 글쓰기 능력이 덜 중요해진 것 같습니다. AI를 사용하면 글이 서투른 사람들도 양질의 직원을 생성할 수 있습니다.