[英]Manipulating the first item in a list in Python
I am working on my first python project.我正在做我的第一个 python 项目。
I am pulling user information from google sheets into a script with gspread.我正在将用户信息从谷歌表格中提取到带有 gspread 的脚本中。
From gspread I am pulling first name, last name, email, etc.从 gspread 我正在提取名字、姓氏、电子邮件等。
I need to manipulate these data points into a new datapoints: username我需要将这些数据点操作成一个新的数据点:用户名
Username for John Smith would be jsmith (first initial last name) John Smith 的用户名将是 jsmith(第一个首字母姓氏)
gspread pulls the cells as a list, ie [John, Smith] gspread 将单元格作为列表拉出,即 [John, Smith]
How would I go about creating the logic to pull the first letter from the first item in the list, then adding it to the second item in the list.我将如何创建逻辑以从列表中的第一项中提取第一个字母,然后将其添加到列表中的第二项中。
Thanks!谢谢!
nameList = ["John", "Smith"]
# Grab the first letter of the first element in the list then combine it to the second element of the list
nameList[0][0] + nameList[1]
Output:输出:
'JSmith'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.