我有一个带有很多 if/elseif 语句的函数。我正在寻找一种方法来改进此函数的代码,替换 IF/ELSEIF。我正在尝试使用字典,但我不确定这是否是最好的方法。提高可读性也很重要。
\nif lowestDim == "Campaign" || lowestDim == "Adgroup"\n if campaignType != "PERFORMANCE_MAX"\n drillThroughMap["DRILLLINK5"] = Dict(\n "filters" => lowestDim == "Campaign" ? Dict([\n SQLFilter("CAMPAIGN", "=", onlyCampaign), SQLFilter("SOURCE", "=", source)]) : Dict([\n SQLFilter("CAMPAIGN", "=", onlyCampaign), SQLFilter("SOURCE", "=", source), SQLFilter("ADGROUP", "=", adgroup)]),\n "drillTo" => demographicDashboard\n )\n end\n drillThroughMap["DRILLLINK10"] = Dict(\n "filters" => Dict(),\n "drillTo" => campaignComparisonDashboard\n )\nend\n\nif presetDateRange != "Last 12+ Months" && (lowestDim != "Keyword" ) && !(source == "google" && (campaignType == "SMART" || campaignType == …Run Code Online (Sandbox Code Playgroud) 我有一本字典,其中的值是列表。我想对字典中的这些列表进行排序。
Dict("Income" => ["Top 10%", "Lower 50%", "31 - 40%", "21 - 30%", "41 - 50%", "Undetermined", "11 - 20%"],
"Age" => ["65+", "55-64", "45-54", "Unknown", "18-24", "25-34", "35-44"],
"Gender" => ["Undetermined", "Female", "Male"],
"Device" => ["Desktop", "Mobile", "Tablet"])
Run Code Online (Sandbox Code Playgroud)
排序后将是:
Dict("Income" => ["11 - 20%", "21 - 30%", "31 - 40%", "41 - 50%", "Lower 50%", "Top 10%", "Undetermined"],
"Age" => ["18-24", "25-34", "35-44", "45-54", "55-64", "65+", "Unknown"],
"Gender" => ["Female", "Male", "Undetermined"],
"Device" => ["Desktop", "Mobile", "Tablet"])
Run Code Online (Sandbox Code Playgroud) 我也有两个键和值的字典作为字典。我正在尝试以将值附加在键中的方式合并这些字典。
Dict{String, Dict{String, String}} with 10 entries:
"8" => Dict("white-space"=>"nowrap", "text-align"=>"left !important")
"4" => Dict("white-space"=>"nowrap", "text-align"=>"left !important")
"1" => Dict("white-space"=>"nowrap", "text-align"=>"left !important")
"24" => Dict("textAlign"=>"left !important")
"5" => Dict("white-space"=>"nowrap", "text-align"=>"left !important")
"2" => Dict("white-space"=>"nowrap", "text-align"=>"left !important")
"6" => Dict("white-space"=>"nowrap", "text-align"=>"left !important")
"7" => Dict("white-space"=>"nowrap", "text-align"=>"left !important")
"9" => Dict("white-space"=>"nowrap", "text-align"=>"left !important")
"3" => Dict("white-space"=>"nowrap", "text-align"=>"left !important")
Run Code Online (Sandbox Code Playgroud)
Dict{String, Dict{String, String}} with 2 entries:
"2" => Dict("min-width"=>"58px !important", "max-width"=>"58px !important")
"3" => Dict("min-width"=>"58px !important", "max-width"=>"58px !important")
Run Code Online (Sandbox Code Playgroud)
我想以附加相同键的值的方式合并这些字典。
Dict{String, Dict{String, String}} with 10 …Run Code Online (Sandbox Code Playgroud) julia ×3