[SOLVED] function for getting a value in a list

Issue

I need to create a function that accepts 1 argument (goblet) and return an empty list or a representation of [x, y] of a goblet.


def formate_a_goblet(goblet):


GOBLET_REPRESENTATION = {
    1: ["▫", "◇", "◯", "□"],
    2: ["▪", "◆", "●", "■"], }    

if goblet == []:    
    return ""

else:
    ....

print(formater_un_gobblet([1, 2]))
>>> "◇"

Solution

Given a list of 2 numbers [x, y], we need to return the symbol present in the dictionary GOBLET_REPRESENTATION with key as x, and value at index y-1.

I tried it like this:

def fun(goblet):
   GOBLET_REPRESENTATION = {
    1: ["▫", "◇", "◯", "□"],
    2: ["▪", "◆", "●", "■"], }
   if goblet == []:
     return ""
   else:
     return GOBLET_REPRESENTATION[goblet[0]][goblet[1]-1] 

Answered By – im_mgn

Answer Checked By – Mary Flores (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.