julia與python類似之處
1.使用列表推導計算笛卡兒積
>>> colors = ['black', 'white'] >>> sizes = ['S', 'M', 'L'] >>> tshirts = [(color, size) for color in colors for size in sizes] ➊ >>> tshirts [('black', 'S'), ('black', 'M'), ('black', 'L'), ('white', 'S'), ('white', 'M'), ('white', 'L')] #julia除了表示字串要用雙引號,其餘照抄 julia> colors = ['black', 'white'] ERROR: syntax: invalid character literal julia> colors = ["black", "white"] 2-element Array{String,1}: "black" "white" julia> sizes = ["S", "M", "L"] 3-element Array{String,1}: "S" "M" "L" julia> tshirts = [(color, size) for color in colors for size in sizes] 6-element Array{Tuple{String,String},1}: ("black", "S") ("black", "M") ("black", "L") ("white", "S") ("white", "M") ("white", "L")
2.生成器表示式
>>> colors = ['black', 'white'] >>> sizes = ['S', 'M', 'L'] >>> for tshirt in ('%s %s' % (c, s) for c in colors for s in sizes): ➊ ... print(tshirt) ... black S black M black L white S white M white L #julia除了輸出格式字串不同,其餘照抄 julia> colors = ["black", "white"] 2-element Array{String,1}: "black" "white" julia> sizes = ["S", "M", "L"] 3-element Array{String,1}: "S" "M" "L" julia> for tshirt in ("$c, $s" for c in colors for s in sizes) println(tshirt) end black, S black, M black, L white, S white, M white, L #生成器表示式可以賦值給一個變數 julia> ge=("$c, $s" for c in colors for s in sizes) Base.Iterators.Flatten{Base.Generator{Array{String,1},##17#19}}(Base.Generator{A rray{String,1},##17#19}(#17, String["black", "white"])) julia> for tshirt in ge println(tshirt) end black, S black, M black, L white, S white, M white, L
相關文章
- Matlab、Julia與Python之間的對比 | Toby DriscollMatlabPython
- 01 . Go之從零實現Web框架(類似Gin)GoWeb框架
- 廣度優先與深度優先類似嗎? - Mario
- 如何實現類似 lodash 的 get 與 merge 函式函式
- 豬行天下之Python基礎——8.1 類與物件Python物件
- Python 3 學習筆記之類與例項Python筆記
- 最大似然分類器
- Tantivy與Quickwit:類似Lucene的Rust全文搜尋引擎庫UIRust
- CSV檔案讀取效能大決戰:Julia 、Python與R語言 - DeepakPythonR語言
- Python元類與列舉類Python
- 26.python之類Python
- 類似gitbook的wiki選擇Git
- mysql 效果類似split函式MySql函式
- LiveKit:使用Go與WebRTC實現類似Zoom高影片質量GoWebOOM
- Python基礎之:Python中的類Python
- Sql Server資料庫類似正規表示式的字元處理問題SQLServer資料庫字元
- Julia:調查顯示76% 的 Julia 使用者將 Python 作為首選替代語言Python
- Python_json資料檢索與定位之jsonPath類庫PythonJSON
- Python之檔案處理Python
- PostgreSQL類似OracleMERGE功能的實現SQLOracle
- RabbitMQ推出類似Kafka的流StreamMQKafka
- ElasticSearch類似Mysql的not in 和 in 查詢ElasticsearchMySql
- VSCode中類似Postman的外掛VSCodePostman
- 碾壓Python!為什麼Julia速度這麼快?Python
- iOS動畫系列之七:實現類似Twitter的啟動動畫iOS動畫
- Python中的類與物件Python物件
- Python基礎-類與物件Python物件
- Julia 嚐鮮
- 類與類之間的基本關係
- go實現類似與spring的全域性上下文獲取getPrincipal()GoSpring
- Python 簡明教程 --- 19,Python 類與物件Python物件
- python異常處理之returnPython
- Kotlin 與 JAVA 不同之處KotlinJava
- 類似淘票票 選座功能(svg)SVG
- 小程式底部彈框 類似picker效果
- “警車”的“警燈”,類似於GIF
- PowerToys外掛擴充套件(類似Alfred)套件Alfred
- Python科普系列——類與方法(下篇)Python
- Python科普系列——類與方法(上篇)Python