Scraping the names of a whole category with a three-liner code
I would add more lines, but improve on performance:


parse only the relevant parts of the page with SoupStrainer
re-use the same session when making requests


Improved version:

import requests
from bs4 import BeautifulSoup, SoupStrainer


URL_TEMPLATE = "https://www.yellowpages.com/search?search_terms=coffee&amp;geo_location_terms=Los+Angeles%2C+CA&amp;page={0}"

parse_only = SoupStrainer("h2", class_="n")

with requests.Session() as session:
    for page_number in range(1, 52):
        response = session.get(URL_TEMPLATE.format(page_number))

        soup = BeautifulSoup(response.content, "lxml", parse_only=parse_only)
        for title in soup.select("h2.n"):
            print(title.get_text())


Also note a variable name change - page_number would be more descriptive than i.