如果我有2个列表:
list1 = ['1', '2', '3', '4']
list2 = ['a', 'b', 'c', 'd']
如何获得包含输出的第三个列表
list3 = ['1a', '2b', '3c', '4d']
我尝试过Zip and Join
但是Zip仍将项目分隔开,而Join会完全删除所有分隔符
谢谢大家!
答案 0 :(得分:2)
如果不定义变量a
,b
...,那么您的第二个列表毫无意义,除非您是指字符串?
list1 = [1, 2, 3, 4]
list2 = ["a", "b", "c", "d"]
list3 = [str(x) + y for x, y in zip(list1, list2)]
答案 1 :(得分:0)
要将两个列表中的两个项目组合为字符串,您需要同时遍历两个列表,并将两个项目串联为字符串。
LayoutBuilder(
builder: (context, constraints) {
return SingleChildScrollView(
child: ConstrainedBox(
// This ensures that the Stack fills the entire viewport,
// even if the Column is small.
constraints: BoxConstraints(
minHeight: constraints.maxHeight,
),
child: Stack(
// Place the only non-positioned child (the column) at the bottom
alignment: Alignment.bottomCenter,
children: [
Column(
mainAxisSize: MainAxisSize.min,
children: [ /* ... */ ]
)
]
)
)
);
}
)
输出将是:
<iframe id="streaming-global-iframe" class="embed-responsive-item" style="width:100%;" src="https://play.sg.video/tree/?v=blancoIG7as" frameborder="0" allowfullscreen webkitallowfullscreen mozallowfullscreen oallowfullscreen msallowfullscreen></iframe>