Input, on the same line, of a string without spaces and another with spaces

Asked

Viewed 301 times

1

My program asks that, at the entrance, on the same line, there be a string space-free name, the name of the applicant, and a string which can contain spaces desc, the description of the deposited object. So that, later, I create a dictionary to relate the name and the object.

Ex input: Ana Bolsa azul

However, the way I did, it is only possible to enter a word at the location of the object description. How to proceed to enter with more than one word down??

As I did:

dic={}

nome,desc=input().split()

dic.update({nome:desc})

1 answer

0


You can change the split to break only at first occurrence

What your code will look like:

dic={}

nome,desc=input().split(" ", 1)

dic.update({nome:desc})
  • Thank you very much! (:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.