我想知道如何搜索字符串列表,如果其中一些在最后一个字母中包含特定的字符。我正在尝试:
import sip
# others imports
class App(QWidget):
def __init__(self):
super().__init__()
# ...
self.popups = [] # <---
def parse(self):
if self.file:
try:
parser = DBParser(self.file)
if parser.isDB():
tablename, fields, rows = parser.getData()
popup = PopUp(tablename, fields, rows) # <---
popup.setAttribute(Qt.WA_DeleteOnClose) # <---
popup.show() # <---
self.popups.append(popup) # <---
else:
QMessageBox.information(self, 'Warning', 'Right format but not CMS DB File')
except:
QMessageBox.critical(self, 'Error', "Invalid File Selected \nMust be .txt or .log format")
self.parse_btn.setEnabled(False)
def closeEvent(self, event):
for popup in self.popups: # <---
if not sip.isdeleted(popup): # <---
w.close() # <---
super(App, self).closeEvent(event)
答案 0 :(得分:0)
如果要查看单个字符,则需要确保将元素强制转换为string
。除此之外,您需要在列表理解中放入if
,以仅选择以uwu
的字符串表示形式结尾的zwz
的那些元素:
uwu=[676, 23, 11]
zwz=3
L_final=[i for i in uwu if str(i)[-1] == str(zwz)]
>>> L_final
[23]