【发布时间】:2018-08-14 20:09:16
【问题描述】:
我正在从外部来源获取我的文件的 header_information,例如如下:
header_information="studentname,branch,collage,place"
之后,我将字符串转换为字符串列表。
headerlist=header_information.split(",")
sid=headerlist[0]
bran=headerlist[1]
coll=headerlist[2]
plc=headerlist[3]
根据我的要求,我必须创建另一个具有指定顺序的列表。 例如:
list1=[coll,plc,sid,bran]
但有时标头会出现不同的(顺序)字符串。
header_information="collage,branch,studentname,place"
but as per my above code :`sid=headerlist[0]`
it will assign `sid=coll`
but i should always assign expected output is like below
sid="studentname"
coll="collage"
bran=="branch"
plc="place
请帮助我。
【问题讨论】:
-
能贴出问题代码吗?您是否也考虑过使用字典来命名您的变量?
-
如何知道元素之间的区别?你不能告诉 python
spiky是狗还是place,除非你构建了一个复杂的 AI 解决方案。
标签: python python-3.x python-2.7 python-requests