我有一个这样的列表:
website = ['http://freshtutorial.com/install-xamp-ubuntu/', 'http://linuxg.net/how-to-install-xampp-on-ubuntu-13-04-12-10-12-04/', 'http://ubuntuforums.org/showthread.php?t=2149654', 'http://andyhat.co.uk/2012/07/installing-xampp-32bit-ubuntu-11-10-12-04/', 'http://askubuntu.com/questions/303068/error-with-tar-command-cannot-install-xampp-1-8-1-on-ubuntu-13-04', 'http://askubuntu.com/questions/73541/how-to-install-xampp']
我想搜索以下列表是否包含某个 URL。
URL 将采用这种格式:url = 'http://freshtutorial.com'
网站是列表的第一个元素。因此,我想打印 1 不是 0。
我希望循环中的所有内容,这样如果没有具有该 URL 的网站,它将再次运行并动态生成列表并再次搜索该网站。
到目前为止我已经这样做了:
for i in website:
if url in website:
print "True"
我似乎无法打印位置并将所有内容包装在循环中。另外,使用 regex
还是 if this in that
语法更好。谢谢
最佳答案
for i, v in enumerate(website, 1):
if url in v:
print i
关于python - 如何找到列表中特定元素的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17784090/