gpt4 book ai didi

python - 如何从python中的MySQL选择列表中删除括号以通过变量值比较列表数据

转载 作者:行者123 更新时间:2023-11-29 07:23:40 25 4
gpt4 key购买 nike

我想从 MySQL 数据库中选择一些行并保存在一个列表中,并与变量值进行比较,但结果为空

这是我的代码:

mycursor = lucas_db.cursor()

mycursor.execute("SELECT Release_Name FROM Lucas_Table WHERE Published_Time > SUBDATE( CURRENT_TIME, INTERVAL 30 MINUTE)")
myresult = mycursor.fetchall()

print(myresult)

last=input('give me:')

me = difflib.get_close_matches(last, myresult)
print(me)

结果是:

[('Food-Fact or Fiction S04E16 Tea Time WEBRip x264-CAFFEiNE',), ('A Million Little Things S01E17 720p HEVC x265-MeGusta',), ('The Pioneer Woman S21E09 16-Minute Chicken 480p x264-mSD',), ('The Pioneer Woman S21E09 16-Minute Chicken AAC MP4-Mobile',), ('Northern Rescue S01E09 720p HEVC x265-MeGusta',), ('Food-Fact or Fiction S04E16 Tea Time XviD-AFG',), ('Food-Fact or Fiction S04E16 Tea Time 480p x264-mSD',), ('Food-Fact or Fiction S04E16 Tea Time AAC MP4-Mobile',), ('How to Get Away with Murder S05E15 720p HEVC x265-MeGusta',), ('The Titan Games S01E09 720p HEVC x265-MeGusta',)]
give me:The Pioneer Woman S21E09 16-Minute Chicken 480p x264-mSD

[]

***Repl Closed***

最佳答案

myresult 将是一个元组列表,其中一个元素是从数据库中选择的单个列。

下面说明了 difflib 的情况。

a = [('foo',),('bar',)]
difflib.get_close_matches('foo', a)
[]
a = [a[0] for a in a]
difflib.get_close_matches('foo', a)
['foo']

关于python - 如何从python中的MySQL选择列表中删除括号以通过变量值比较列表数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54952635/

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