목록 목록이 있습니다
[[name1, value1], [name2, value2], ...]
나는 이름이에서 가져온 이름으로, 즉, 등 NAME2, NAME1과 함께 클래스의 인스턴스를 만들 필요가 list[1][1]
, list[2][1]
등하지만이 구현 될 수있는 방법을 상상할 수 없다.
수업:
class func():
def __init__(self, visibility, ftype, body):
...
명부:
list = [
['private', 'Void', 'SetupWheels', 'body'],
...
]
사전:
func_list = {}
다음과 같아야합니다.
for i, val in enumerate(c):
*new key in the dictionary is equal to the value val[2]* = func(val[0], val[1], val[3])
목록 목록에서 속성을 가져온 클래스의 인스턴스로 사전을 채우려면 다음과 같은 dict
이해를 사용할 수 있습니다 .
func_list = {row[2]: Func(row[0], row[1], row[3]) for row in c}
class Func():
def __init__(self, visibility, ftype, body):
self.visibility = visibility
self.ftype = ftype
self.body = body
def __repr__(self):
return "v:%s f:%s b:%s" % (self.visibility, self.ftype, self.body)
c = [
['private', 'Void', 'SetupWheels', 'body'],
['private', 'Void', 'SetupWheelx', 'bo8y'],
]
func_list = {row[2]: Func(row[0], row[1], row[3]) for row in c}
print(func_list)
{'SetupWheelx': v: private f:Void b:body, 'SetupWheels': v: private f:Void b:body}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다