2014-12-06 3 views
0

변환 PHP 코드 : 파이썬파이썬 : 추가] 사전 새로운 요소

$this->plane[$slice_id][$f][] = array('x' => $y, 'y' => $z);

:

self.plane[slice_id][f][] = {'x' : y, 'y' : z};

self.plane = {};

이 작동하지 않습니다.

1) self.plane[slice_id][f]-> 아직 초기화되지 않았습니다. 필요한 경우이 요소 만 작성하십시오.

2) [] - 배열> 푸시 소자

3) 파이썬 사전

+0

가있는 [무한 defaultdict (http://stackoverflow.com/questions/4178249 파이썬 유효 구문없는/무한 중첩 - 파이썬 사전). –

답변

0

메소드 append()가로 전달 obj를 부가이

self.plane[slice_id][f] = [] 
self.plane[slice_id][f].append({'x' : y, 'y' : z}) 

같은 시도 일반적 다차원 아니다 기존 목록.

self.plane[slice_id][f][] = {'x' : y, 'y' : z};

데모 PHP의 배열에 가까운 파이썬

>>> new_list = [] 
>>> new_list[] = 'test' 
    File "<stdin>", line 1 
    new_list[] = 'test' 
      ^
SyntaxError: invalid syntax