小编And*_*rew的帖子

将嵌套列表更改为多个单个列表

如果我有一个清单:

[[ A, B, C ], 10, [ 1, 2, 3 ], F]
Run Code Online (Sandbox Code Playgroud)

将其更改为的最佳方法是什么:

[ A, 10, 1, F]
[ B, 10, 2, F]
[ C, 10, 3, F]
Run Code Online (Sandbox Code Playgroud)

嵌套列表的长度是一致的:len(list[0]) == len(list[2]),但len(list[0])可能是3, 2, 4,等等。

python list nested-lists

3
推荐指数
1
解决办法
147
查看次数

执行“尝试...除外...”的功能

我想将“尝试...除外...”放入一个函数中,以便我的代码更短,因为它被多次使用。

使这项工作:

def whiletry(x):
    while 1:
        try:
            x
            break
        except:
            time.sleep(0.25)

whiletry(driver.find_element_by_xpath('//*[@id="j_list_card"]/ul/li/h3/a').click())
Run Code Online (Sandbox Code Playgroud)

python selenium python-3.x

0
推荐指数
1
解决办法
69
查看次数

标签 统计

python ×2

list ×1

nested-lists ×1

python-3.x ×1

selenium ×1