Skip to content

Instantly share code, notes, and snippets.

@FGFW
Created March 26, 2016 19:42
Show Gist options
  • Save FGFW/ee5d5bb606f9df9adc1d to your computer and use it in GitHub Desktop.
Save FGFW/ee5d5bb606f9df9adc1d to your computer and use it in GitHub Desktop.
julia文本文件合并去重.jl
#="""
julia文本文件合并去重.jl
http://bbs.bathome.net/thread-39822-1-1.html
2016年3月27日 01:02:58 codegay
"""=#
f1=open("1.txt")
txt1=readlines(f1)
txt2=readlines(open("2.txt"))
txt=vcat(txt1,txt2) #以readlines取读文件流,vcat连接两个Array,julia不支持+号连接字符串和数组,支持$符内插
@show length(txt)
result=unique(txt) #内置函数unique去重
#result=Set(txt) Set()方法把数组转为集合,集合中的元素唯一,Set是首字母大写的!
@show length(result)
write(open("result.txt","w+"),result) #与python不同,julia把数组写入文件不需要wirtelines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment