Home > Back-end >  Need multiple inputs saved to another single input, all information given by user
Need multiple inputs saved to another single input, all information given by user

Time:09-21

Building a webscraper for a game I love and right now came into a little issue with python, what I want to do could best be show as:

userdata = { ' ', [ ]}

I'm new to writing python so my question is would this work given the following scenario: User's account name (which players in the game use to message each other) wants to attach multiple character names to that single account name so other players know that all these characters belong to that one account.

The end result should be something like this:

"Please enter your account name followed by which characters you wish associated with this account:" user input: Leafzer Leaf1 Leaf2 Leaf3

current limitations in the game work to python's advantage as account and character names can not have any white space. I was considering using split such as:

x = [str(x) for x in input("Enter user data: ").split()]

but as it stands neither of these seem to work quite right.

To reiterate and maybe clear some of the confusion: Writing a website scraper that allows players in the game to enter their account name and a list of mules (characters in the game that just hold items). The list of mules and the account name must be separate as my scraper uses the list of mules to go to a certain website using that mule name and downloads the data into a searchable csv file. If another player searches for an item that is within that csv file, it brings up the account name associated with the mule rather than the mule name and displays the account name to player searching for the item.

I'm stuck trying to figure out how to obtain the user data in this manner. Any help would be appreciated.

CodePudding user response:

Are you after something like this:

users = {}
user, *chars = input("Please input your name and characters: ").split(" ")
users[user] = chars

?

Or slightly less confusingly (but not nearly as neatly):

users = {}
words = input("Please input your name and characters: ").split(" ")
user = words[0]
chars = words[1:]
users[user] = chars

But * unpacking is great, and everyone should use it!

P.S. for your second use case, just call input() twice!:

username = input("Please input your name: ")
chars = input("Please input your characters: ").split(" ")
  • Related