Open graciedevine opened 3 years ago
I have a bit different suggestion about this:
from collections import namedtuple
Game = namedtuple("Game", "title,price,tags,platforms")
output = [Game(*info)._asdict() for info in zip(titles, prices, tags, platforms)]
Another approach would be to use custom JSON serializer. Illustrated on dataclass
instead of namedtuple
:
import json
from dataclasses import dataclass
@dataclass(frozen=True)
class Game:
title:str
price:str
tags:list
platforms:list
class EnhancedJSONEncoder(json.JSONEncoder):
def default(self, o):
if dataclasses.is_dataclass(o):
return dataclasses.asdict(o)
return super().default(o)
output = [Game(*info) for info in zip(titles, prices, tags, platforms)]
json.dumps(output, cls=EnhancedJSONEncoder)
cant understand the div class; i try to find the popular release but i couldn't find it! any help or suggestion please?
Thanks
On Tue, Feb 27, 2024 at 4:38 PM Rauan Omirkul @.***> wrote:
cant understand the div class; i try to find the popular release but i couldn't find it! any help or suggestion please?
https://store.steampowered.com/explore/new here is the link. New releases aren't on the homepage
— Reply to this email directly, view it on GitHub https://github.com/yasoob/practical-python-projects/issues/33#issuecomment-1966839800, or unsubscribe https://github.com/notifications/unsubscribe-auth/A4VR6NK735HA5UJOQMMQZGDYVX4WNAVCNFSM423QOGC2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJWGY4DGOJYGAYA . You are receiving this because you commented.Message ID: @.***>
Description
Hello! I was doing the web scraping project in PyCharm and it suggested using a dictionary literal for Lines 27-33. So, instead of:
Possible Solutions
PyCharm suggested writing it as:
I think this would be good to include since list comprehensions are presented in this chapter too.
Your full name so I can provide accurate credit within the book
Gracie Devine