Python 'in' function , pandas dataframe wrongly populated
Question: 
    from collections import defaultdict
    import csv
    from bs4 import BeautifulSoup
    import urllib2
    import pandas as pd
    import re
    
    text = open("/Users/dynajose/Desktop/PlayList.rtf").read()
    songDom = BeautifulSoup(text) 
    
    data=defaultdict(list)
    musicData=defaultdict(list)
    
    f_music = songDom.find_all("div", {"class" : "_gx6 _agv"})
    
    for music in f_music:
        try:
            Name_title = music.find("a","_gx7")
            data['Name'].append(Name_title.text)
        except:
            data['Name'].append("")
    
        try:
            type_title = music.find("div","_1fs8 fsm fwn fcg") 
            data['Type'].append(type_title.text)
        except:
            data['Type'].append("") 
    
    
    for link_music in f_music:
        variable=link_music.find('a', href=re.compile('^https:'))['href']
        data['Link'].append(variable)
    
    
    for verified_page in f_music:
        for page in verified_page:
            page_verified = page.find_all('span',{'aria-label':'Verified Page'})
            #print page_verified
            check= "Verified Page"
            for a in page_verified :
                 if check in a :
                        musicData['Link'].append(True)
                 else :
                        musicData['Link'].append(False)
    
    
    
    
    #if sum([True for a in page_verified if check in a]) > 1:
             #   musicData['Link'].append(True)
            #else :
             #   musicData['Link'].append(False)
    
    
    #df = pd.DataFrame(data)
    dr= pd.DataFrame(musicData)
    #df
    dr
    

* * *

![Print page_verified output](http://i.stack.imgur.com/31g9r.png)

## ![dr output](http://i.stack.imgur.com/lDvEQ.png)

Desired Result - So I want the DataFrame column to be True if the page is
Verified. Wether a page is verified or not is defined by the span tag and
aria-label tag. (DataFrame is Boolean)

My logic- I will append True if the row has "Verified page" in it. else False.

But in this case all rows have "Verified Page" in it yet it goes to the else
part.

Is there any function in Python that helps me do it more efficiently or any
better way to achieve the desired result?


Answer: Looks like your `page_verified` variable is actually a list, that's why your
check returns false.

Example :

    
    
    l = ['ab']
    'a' in l
    False
    

If the list returned is always containing one element, just do

    
    
    if check in page_verified[0]:
    

if the returned list can be multi elements, you can try something like
(probably a better way to do it, but it'll work)

    
    
    if sum([True for a in page_verified if check in a]) > 1:
    

** edit**

Please provide output of this so we can have more info

    
    
    for music in f_music:
        for verified_page in f_music:
            for page in verified_page:
                page_verified = page.find_all('span',{'aria-label':'Verified Page'})
                print page_verified
                check= "Verified Page"
                print page_verified[0]
                print type(page_verified[0])
                print check in page_verified[0]
    

