dict = {}
name_surname = input("Enter your name and surname: ").split(" ")
dict["Name and surname"] = name_surname
print(dict)
我需要这样做,以便当用户输入他们的名字和姓氏(例如:Michael Jokester Scott)时,它将把名字和用户名分开,以便我以后可以分别使用它们。
这样做的目的是能够随机组合某人的名字和姓氏,并附加一个"@gmail.com"最后。这样你就得到了随机的结果。但是个人电子邮件地址。所以最后,我应该能够创建一个随机的电子邮件,如:"jokester.scott.michael@gmail.com.">
到目前为止我掌握的非常糟糕,我是Python新手,我不太了解字典,列表对我来说更容易,但我也需要学习这个。
如果我理解正确的话,你可以在字典中使用列表。
sample_dct['Name and Surname'] = []
# take input from user
name_surname_list = taken_data_from_user.split()
sample_dct['Name and Surname'].append(name_surname_list)
# get sample_dct values, iterate on these with a loop
# generate 2 random number range between (0,len(sample_dct)) use generated these random numbers to take random value.
# for surname, use [-1] index and store random_surname; for name, use [:-1] and store random_name.
random_name_full = '.'.join(random_name)
random_mail = '.'.join(random_name_full ,random_surname) + '@gmail.com'
这是你要找的吗?你永远不知道你会得到什么名字。
dict_data = {}
name_surname = input("Enter your name and surname: ").split(" ")
arr_size = len(name_surname)
def name(data):
count = 1
if arr_size == len(data):
dict_data['name'] = data[0]
data.pop(0)
dict_data['last_name'] = data[-1]
data.pop(-1)
while arr_size > len(data) != 0:
name = 'middle_name_' + str(count)
dict_data[name] = data[0]
data.pop(0)
count += 1
name(name_surname)
print(dict_data)