1

次のようなリストがあります。

 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'

ウェブサイトはリストの最初の要素です。したがって、 0 ではなく1 を出力したいと思います。

その URL を持つ Web サイトがない場合は、再び実行して動的にリストを生成し、Web サイトを再度検索するように、すべてをループに入れたいと考えています。

私は今までこれを行ってきました:

for i in website:
    if url in website:
        print "True"

位置を印刷してすべてをループでラップすることができないようです。また、構文を使用する方が良いですregexか。if this in thatありがとう

4

3 に答える 3

2
for i, v in enumerate(website, 1):
    if url in v:
        print i
于 2013-07-22T09:36:29.093 に答える
1

コード -

for i in range(0,len(website)):
    current_url = website[i]
    if url in current_url:
         print i+1

シンプルな for ループです。

于 2013-07-22T09:43:55.337 に答える