I have a function in Python that is called by a map() function iterating over all the elements of a list which are sent as parameters. This function returns a dictionary and the map function is assigned to a dictionary, but the Python interpreter converts it into a list.
hotels_with_low_wifi_quality = pool.map(get_accomodation_wifi_rating, hotels_url_list)
So in the sentence above, hotels_with_low_wifi_quality is a dictionary and get_accomodation_wifi_rating is a function that returns a dictionary.
But if I print hotels_with_low_wifi_quality it outputs the following:
[None, None, None, None, None, None, None, None, None, {u'\nPins Platja\n': u'4,3'}, None, None, None, None, None] None
This is clearly a list. How can I convert it into a dictionary where the None values are ignored and the only element is ["Pins Platja"] = 4.3
Below is the get_accomodation_wifi_rating
def get_accomodation_wifi_rating(hotel):
page = requests.get(hotel)
soup = BeautifulSoup(page.text, 'lxml')
hotel_name = soup.find(id = "hp_hotel_name").text
reviews = soup.find(class_="review_list_score_breakdown_right")
if reviews is not None:
wifi_tag = reviews.find(attrs={"data-question" : "hotel_wifi"})
if wifi_tag is not None:
wifi_rating = wifi_tag.find(class_="review_score_value")
wifi_score = wifi_rating.text
wifi_score_num = wifi_score.replace(",", ".")
if float(wifi_score_num) < 7:
hotels_with_low_wifi_quality[hotel_name] = wifi_score
return hotels_with_low_wifi_quality