请教一下 有关字典的代码问题

78]:
sex = [“F”, “M”, “M”, “F”, “M”]
freqs = Dict()
for xi in sex
if xi in keys(freqs)
freqs[xi] += 1
else
freqs[xi] = 1
end
end
freqs
请问image 这个要怎么解释呢。我想了半天还是不懂,这个代码是对某个离散取值的变量计算其频数表, 即每个不同值出现的次数。 如果不利用字典类型, 可以先找到所有的不同值, 将每个值与一个序号对应, 然后建立一个一维数组计数, 每个数组元素与一个变量值对应。

贴代码你用
```julia
code here
```
你的问题好像没说清楚啊

前辈 我明白了。 刚刚因为代码没读懂,不明白啥意思。前辈能在问一个问题吗image 就是途中划红线的部分 为什么要加逗号呢

在提问之前请确定你已经努力阅读了文档,并且尝试自己在互联网上搜索。

请尽可能提供你的demo代码或者GitHub的gist地址。

# code

你这个问题只要看下 println 的说明文档就明白了,输出多个东西中间用 , 分割

code here
A = [1,2,3;,4,5,6]
for i = 1:size(A1,2),j =1: size(A1,2)
 println("A1[",i,",",j,"]=",A1[i,j])
end

A = [1,2,3;,4,5,6]
for i = 1:size(A1,2),j = 1:size(A1,2)
 println("A1["i","j"]=",A1[i,j])           #此处不能正确输出
end

前辈不好意思,我想冒昧的问一下上下两个代码第一个可以正确输出,第二个不可以,为什么第一个在“ ”内加了,就可以正常输出

这个是基础问题,第二个不可以正常输出是因为julia没法理解你这个"A1["i","j"]=", 按照规则你这个会被解析成

"A1["  i  ","   j   "]="

一共三个部分(其实是没有中间的空格的,加上空格便于你理解),这个东西 Julia 没法理解你想干什么。
至于第一个为啥可以正常输出,你看下 println 的文档就知道了,你不愿意看的话,我帮你查一下。

help?> println
search: println printstyled print sprint isprint

  println([io::IO], xs...)

  Print (using print) xs followed by a newline. If io is not supplied, prints to stdout.

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> println("Hello, world")
  Hello, world
  
  julia> io = IOBuffer();
  
  julia> println(io, "Hello, world")
  
  julia> String(take!(io))
  "Hello, world\n"

help?> print
search: print println printstyled sprint isprint prevind parentindices precision escape_string setprecision unescape_string process_running CapturedException ProcessFailedException

  print([io::IO], xs...)

  Write to io (or to the default output stream stdout if io is not given) a canonical (un-decorated) text representation. The representation used by print includes minimal formatting and tries to avoid Julia-specific details.

  print falls back to calling show, so most types should just define show. Define print if your type has a separate "plain" representation. For example, show displays strings with quotes, and print displays strings without quotes.

  string returns the output of print as a string.

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> print("Hello World!")
  Hello World!
  julia> io = IOBuffer();
  
  julia> print(io, "Hello", ' ', :World!)
  
  julia> String(take!(io))
  "Hello World!"

以你目前的水平,建议你先看完 Julia 中文文档

明白了谢谢前辈 :smile:

不要喊前辈,除非你是女的

对于需要在字符串内部穿插大量变量的情况,可以使用字符串插值:

julia> a,b,c,d=1,2,3,4
(1, 2, 3, 4)

julia> "a=$a, b=$b, c=$c, d=$d"
"a=1, b=2, c=3, d=4"

谢谢 :smile: