列出人员姓名

2024-09-30 18:23:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在寻找一个问题的解决方案,我正在尝试在Python上列出一个列表,它有一种与人和一套技能(John=forklifk-Trained,CDL,Jackhammer,electrician.)一起列出一个列表的方法,类似的,但是有20个名字和组织领导者学位可以使用的每一个行业?有人能帮我吗?你知道吗


Tags: 方法列表技能解决方案名字john行业cdl
2条回答

print('worker:{}具有以下技能:{}'。格式(k,employees[k])) 对于k in循环

您没有在这里提供任何代码来向我们展示您试图解决问题的方法,也没有说明您对python的了解程度,因此很难理解您处理此问题的背景。你知道吗

这里有一个可能的解决方案:创建一个包含不同员工姓名的字典,并为字典中的每个键分配一个包含该员工技能的数组。你知道吗

例如:

employees = {}
employees['John'] = ["ForkLift Trained", "CDL", "Jackhammer", "electrician"]
employees['Brian'] = ["Computer Scientist", "Programmer"]

print(employees)

for k in employees:
    print('worker: {} has the following skills: {}'.format(k, employees[k]))

显然,print函数的格式可以根据需要进行更改,但这只是一般的想法。你知道吗

此代码的输出为:

{'John': ['ForkLift Trained', 'CDL', 'Jackhammer', 'electrician'], 'Brian': ['Computer Scientist', 'Programmer']}
worker: John has the following skills: ['ForkLift Trained', 'CDL', 'Jackhammer', 'electrician']
worker: Brian has the following skills: ['Computer Scientist', 'Programmer']

同样,这只是一个粗略的想法,你所描述的问题是相当普遍的,可以用许多不同的方法来解决,除非你提供更多的信息。你知道吗

编辑:打印每个员工的姓名和技能的功能是:

for k in employees:
    print('worker: {} has the following skills: {}'.format(k, employees[k]))

如果字典(使用employees ={}声明)中加载了足够的工作线程,则此函数将用于打印单个工作线程或1000个工作线程。 每个员工都有自己的独立生产线。你知道吗

为了在不同的行中打印具有不同技能的员工的姓名,可以使用以下内容:

for k in employees:
    print('{} has the following skills:'.format(k))
    for i in employees[k]:
        print(i)
    print()

输出为:

John has the following skills:
ForkLift Trained
CDL
Jackhammer
electrician

Brian has the following skills:
Computer Scientist
Programmer

相关问题 更多 >