我偶然发现了一个问题,即Java子列表不返回列表实例但返回列表视图.这导致线程卡住了.
我做了一些谷歌搜索,发现了这一点.
我创建了一个看起来像这样的列表:
items = [["one","two","three"], 1, ["one","two","three"], 2]
Run Code Online (Sandbox Code Playgroud)
如何在此列表中访问例如"1"?
尊敬的亲爱的社区,
在这篇文章之后,
我正在搜索如何从包含多个具有不同名称的子列表的列表中创建多个数据框
因此,从名单中tier.col 我想创建一个函数tier2col,该函数返回多个data.frames(与我的列表中的子列表一样多),其中包含子列表的特定元素.
我得到如何手动执行此操作:
phones <- data.frame(tier.col$phones$xmin[-1,3], tier.col$phones$xmax[-1,3], tier.col$phones$text[3])
Run Code Online (Sandbox Code Playgroud)
但实际上"手机"会改变多个名称,因此我需要一种更通用的方法来制作子列表:
x <- data.frame(tier.col$x$xmin[-1,3], tier.col$x$xmax[-1,3], tier.col$x$text[3])
Run Code Online (Sandbox Code Playgroud)
该功能将如下:
tier2col <- function(list.x) {
for all sublist in my list
select tier.col$sublist$xmin[-1,3], tier.col$sublist$xmax[-1,3], tier.col$sublist$text[3]
and compile them in a dataframe
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以通过这个调用所有的xmin&xmax&text:
lapply(tier.col[c(1:length(names(tier.col)))], "[", 1)
lapply(tier.col[c(1:length(names(tier.col)))], "[", 2)
lapply(tier.col[c(1:length(names(tier.col)))], "[", 3)
但我不知道如何通过这种或如何在这种数据结构上使用mapply.
我希望有类似的tier.col$c(names(tier.col)$xmin工作,但显然,这不是正确的方法.
有人可以帮助我以有效的方式计算这个吗?
结构tier.col:
List of 17
$ phones :List of 3
..$ xmin:'data.frame': 2506 obs. of 3 …Run Code Online (Sandbox Code Playgroud) 说我有一份清单
X=[[0,0,0,3,4],[8,8,9,2,8,2]]
如何使每个子列表只包含一次重复的数字:
像这个新列表:
XNew=[[0,3,4],[8,9,2]]
我想得到一个嵌套列表中子列表的索引位置,例如nested [1]中的[1,2],[[1,2],[3,4]].获取子列表索引的最优雅方法是什么,是否有类似于index()的东西?
我在Windows 7中使用Python 3.4和Wing Personal.我有一个int列表和第二个包含3个int的列表.我想确定list [b]的所有3个元素出现在列表[a]中的次数.
a=[[1, 6, 11,12, 14, 15], [4, 11, 23, 32, 45, 48],
[3, 7, 11, 14, 15, 17], [1, 8, 14, 24, 45, 53],
[2, 5, 9, 24, 34, 40], [10, 11,13, 14, 15, 22, 36]]
b=[11,14,15]
count =0
anotherList = []
for sublist in a:
for element in b:
if element in sublist:
anotherList.append(element)
count+=1
print (anotherList)
print (count/3)
Run Code Online (Sandbox Code Playgroud)
这里的计数应该是3,而不是3.6,而如果列表[a]包含20个子列表,并且在子列表的6个中发生单个14,则无法解决这个问题.
问题是这计算列表[b]中任何元素出现在列表[a]中的总次数,而不是所有3个元素的模式.我除了3分,这会使计数正确,直到我意识到如果一个列表中只有14个也被计算,那么计数将被关闭.
请注意,每个列表中的索引都不同,有时在我想要识别的元素之间会出现另一个元素.也就是说,元素并不总是在一起,如11,14,15.有时候介于两者之间.
我考虑过删除除11,14,15之外的所有数字然后删除少于3个元素的所有列表,但不知何故,这似乎不是这样做的方式.
任何帮助表示赞赏.
非常自我解释......
这个:
{"hello","this","is","an","example","string"}
Run Code Online (Sandbox Code Playgroud)
会回来:
{
{"is","an"},
{"this"},
{"hello"},
{"string"},
{"example"}
}
Run Code Online (Sandbox Code Playgroud) 假设我有一份清单清单.子列表本身可以包含子列表.将所有子列表的所有元素转换为特定类型的有效方法是什么?
让我们说它像这样凌乱:
a = [
1,
2,
3,
[
"a",
"b"
],
[
10,
20,
[
"hello",
"world"
]
],
4,
5,
"hi",
"there"
]
Run Code Online (Sandbox Code Playgroud)
我的想法是将类似的内容转换为:
a = [
"1",
"2",
"3",
[
"a",
"b"
],
[
"10",
"20",
[
"hello",
"world"
]
],
"4",
"5",
"hi",
"there"
]
Run Code Online (Sandbox Code Playgroud)
请注意,我正在寻找处理任意深度的子列表的方法.我有一种感觉,可以使用发电机,但我不知道如何处理这个问题.