gpt4 book ai didi

ios - 根据条件将数组合并到字典中?

转载 作者:行者123 更新时间:2023-11-28 08:59:47 24 4
gpt4 key购买 nike

我有两个数组:

First array = ["lines","lines","lines","lines"]
Second array = ["one","two","","three","four","","five","six","","seven","eight"]

我想将它们合并到一个带有嵌套数组的字典中:

Dict = ["lines":["one","two"],"lines":["three","four"],"lines":["five","six"],"lines":["seven","eight"]]

基本上,由于空格标准 (""),第二个数组中的值应该被拆分,并在字典中分配为单独的数组对象。

最佳答案

试试这个解决方案:

let array2 = ["one","two","","three","four","","five","six","","seven","eight"] 
var splittedArray = array2.split { $0 == "" }

Playground 的结果: enter image description here

重要提示:我使用的是 Xcode 7 iOS 9

关于ios - 根据条件将数组合并到字典中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32185803/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com