Home > Back-end >  How to extract only the first sentence from the dictionary?
How to extract only the first sentence from the dictionary?

Time:12-11

I'm trying to create a game in python called "Save the girl" One man will kidnap a girl and will keep him in his place and ask money from her family.

To reach his place he will ask three questions. First he will ask one question and if they answer it then he will give a clue to reach his place.

For this I'm storing all the questions and answer in a form of dictionary

Eg:

Quiz_dict={"What did the Romans call Scotland?":"Japan","Which company makes the Galaxy 
              series of smartphones?":"Samsung"}

Now I just want the first question from the dictionary. How to do that??

I gave the command like

keys = "".join(list(Quiz_dict.keys()))
    print(keys[0])

But the output was the first letter of the first question (ie.W). Please help me out

CodePudding user response:

list(Quiz_dict)[0] 

should serve the purpose

CodePudding user response:

Ofourse It should Be that. What have You done is You have joined the both questions and then FIRST [0] is W.

quiz.keys()  = dict_keys(['What did the Romans call Scotland?', 'Which company makes the galaxy series of smartphones> '])

Now list(quiz.keys()) converts it into a list which we can slice

list(quiz.keys())[0] --> this gives 'What did the Romans call Scotland?'
  • Related