DEV Community

Cover image for Ibuprofeno.py💊| #106: Explica este código Python
Cristian Fernando
Cristian Fernando

Posted on • Edited on

Ibuprofeno.py💊| #106: Explica este código Python

Explica este código Python

Dificultad: Fácil

MLB_team = {
    'Colorado' : 'Rockies',
    'Boston'   : 'Red Sox',
    'Minnesota': 'Twins',
    'Milwaukee': 'Brewers',
    'Seattle'  : 'Mariners'
}

print(MLB_team[-1])
Enter fullscreen mode Exit fullscreen mode

👉 A. Mariners
👉 B. KeyError
👉 C. Rockies
👉 D. -1


Respuesta:

👉 B. KeyError

Los diccionarios no pueden ser tratados como listas, no es posible acceder al último elemento de diccionario MLB_team haciendo MLB_team[-1]. Los diccionarios no tienen las mismas propiedades que las listas.

Top comments (0)

Eliminate Context Switching and Maximize Productivity

Pieces.app

Pieces Copilot is your personalized workflow assistant, working alongside your favorite apps. Ask questions about entire repositories, generate contextualized code, save and reuse useful snippets, and streamline your development process.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay