회원 로그인
|
Python for Maya - 6. 리스트 자료 다루기 2
기반으로 복습하는 차원에서 재정리한 것입니다.
이번엔 리스트의 자료 추가, 삭제, 운용에 대해서 알아보겠다.
이 모든 작업은 저장된 리스트를 추가 및 삭제를 하게 되면 실 object에는 영향이 없다는 점이다.
object들을 마구잡이로 랜덤하게 선택하자.
import maya.cmds as cmd sel_ = cmd.ls(sl=1) sel_ # Result: [u'nurbsSphere9', u'nurbsSphere3', u'nurbsSphere6', u'nurbsSphere2', u'nurbsSphere10', u'nurbsSphere1', u'nurbsSphere7', u'nurbsSphere8', u'nurbsSphere4', u'nurbsSphere5'] #자료들이 랜덤하게 들어가 있다.
자료의 갯수, 길이를 구할 땐 len(리스트명)
len(sel_) # Result: 10 #원하는 자료의 갯수를 구할 땐 리스트명.count('자료')
sel_.count('nurbsSphere3') # Result: 1 #원하는 자료의 위치를 구할 땐 리스트명.index('자료')
sel_.index('nurbsSphere3') # Result: 1 #원하는 자료를 삭제할 땐 리스트명.remove('자료')
sel_.remove('nurbsSphere3') sel_ # Result: [u'nurbsSphere9', u'nurbsSphere6', u'nurbsSphere2', u'nurbsSphere10', u'nurbsSphere1', u'nurbsSphere7', u'nurbsSphere8', u'nurbsSphere4', u'nurbsSphere5'] #리스트의 nurbsSphere3 자료가 삭제되었다.
원하는 위치의 자료를 삭제할 때 del 리스트명[자료위치]
del sel_[3] sel_ # Result: [u'nurbsSphere9', u'nurbsSphere6', u'nurbsSphere2', u'nurbsSphere1', u'nurbsSphere7', u'nurbsSphere8', u'nurbsSphere4', u'nurbsSphere5'] #3번째에 위치한 nurbsSphere10 자료가 삭제되었다.
자료를 추가할 때 리스트명.append(u'자료')
(시퀀스 자료형이라 추가할 땐 맨뒤에 위치하게 된다.)
sel_.append(u'nurbsSphere3') sel_ # Result: [u'nurbsSphere9', u'nurbsSphere6', u'nurbsSphere2', u'nurbsSphere1', u'nurbsSphere7', u'nurbsSphere8', u'nurbsSphere4', u'nurbsSphere5', u'nurbsSphere3'] #리스트 맨 뒤에 nurbsSphere3 자료가 추가되었다.
지정된 위치에 자료를 삽입할 때 리스트명.insert(위치번호, '자료')
sel_.insert(3, u'nurbsSphere9') sel_ # Result: [u'nurbsSphere9', u'nurbsSphere6', u'nurbsSphere2', u'nurbsSphere9', u'nurbsSphere1', u'nurbsSphere7', u'nurbsSphere8', u'nurbsSphere4', u'nurbsSphere5', u'nurbsSphere3'] #삽입 다른 방법 리스트명[시작번호:끝번호] = [u'자료']
sel_[3:3] = [u'nurbsSphere7'] sel_ # Result: [u'nurbsSphere9', u'nurbsSphere6', u'nurbsSphere2', u'nurbsSphere7', u'nurbsSphere9', u'nurbsSphere1', u'nurbsSphere7', u'nurbsSphere8', u'nurbsSphere4', u'nurbsSphere5', u'nurbsSphere3'] #자료 끝에 넣을 때 리스트명 +- [u'자료']
sel_ += [u'temp'] sel_ # Result: [u'nurbsSphere9', u'nurbsSphere6', u'nurbsSphere2', u'nurbsSphere7', u'nurbsSphere9', u'nurbsSphere1', u'nurbsSphere7', u'nurbsSphere8', u'nurbsSphere4', u'nurbsSphere5', u'nurbsSphere3', u'temp'] #리스트 맨 뒤에 temp 자료가 추가되었다.
중복된 자료 정리할 때
sel_.count('nurbsSphere9') # Result: 2 # // count로 확인 sel_ = list(set(sel_)) sel_ # Result: [u'nurbsSphere9', u'nurbsSphere8', u'temp', u'nurbsSphere3', u'nurbsSphere2', u'nurbsSphere1', u'nurbsSphere7', u'nurbsSphere6', u'nurbsSphere5', u'nurbsSphere4'] #중복 된 nurbsSphere7 자료도 같이 정리 되었다.
sel_.count('nurbsSphere9') # Result: 1 #리스트 자료를 이름순으로 정리할 때 리스트명.sort()
sel_.sort() sel_ # Result: [u'nurbsSphere1', u'nurbsSphere2', u'nurbsSphere3', u'nurbsSphere4', u'nurbsSphere5', u'nurbsSphere6', u'nurbsSphere7', u'nurbsSphere8', u'nurbsSphere9', u'temp'] #높은 순으로 리스트의 자료가 정리되었다.
리스트 자료를 역순으로 바꿀 때 리스트명.reverse()
sel_.reverse() sel_ # Result: [u'temp', u'nurbsSphere9', u'nurbsSphere8', u'nurbsSphere7', u'nurbsSphere6', u'nurbsSphere5', u'nurbsSphere4', u'nurbsSphere3', u'nurbsSphere2', u'nurbsSphere1'] #리스트의 자료들이 낮은 순으로 정리되었다.
리스트 자료와 자료를 합칠 때 리스트명.extend([u'자료', ....])
sel_.extend([u'nurbsSphere4',u'nurbsSphere4',u'nurbsSphere4',u'nurbsSphere4']) sel_ # Result: [u'temp', u'nurbsSphere9', u'nurbsSphere8', u'nurbsSphere7', u'nurbsSphere6', u'nurbsSphere5', u'nurbsSphere4', u'nurbsSphere3', u'nurbsSphere2', u'nurbsSphere1', u'nurbsSphere4', u'nurbsSphere4', u'nurbsSphere4', u'nurbsSphere4'] #리스트 맨 뒤에 자료를 합친다.
리스트 자료와 자료를 합칠 때 다른 방법 리스트명 +- [u'자료', ....])
sel_ += [u'nurbsSphere8', u'nurbsSphere8', u'nurbsSphere8'] sel_ # Result: [u'temp', u'nurbsSphere9', u'nurbsSphere8', u'nurbsSphere7', u'nurbsSphere6', u'nurbsSphere5', u'nurbsSphere4', u'nurbsSphere3', u'nurbsSphere2', u'nurbsSphere1', u'nurbsSphere4', u'nurbsSphere4', u'nurbsSphere4', u'nurbsSphere4', u'nurbsSphere8', u'nurbsSphere8', u'nurbsSphere8'] #리스트 맨 뒤에 자료들이 추가되었다.
이번에는 조건 검사를 하는 방법에 대해서 알아 보겠다.
자료를 줄이가 위해 위 방법을 복습하여 정리해 하자.
sel_ # Result: [u'nurbsSphere9', u'nurbsSphere8', u'nurbsSphere7', u'nurbsSphere4'] #리스트 안에 존재 여부 확인 하려면 '자료' in 리스트명
'nurbsSphere7' in sel_ # Result: True # // 있으면 False 'nurbsSphere1' in sel_ # Result: False # // 없으면 False
────────────────────────────────────────────────
source : http://cafe.naver.com/digitaldream/447 - 'Maya Python 시작하기' 6) 자료 다루기 - 2
댓글 0개
| 엮인글 0개
466개(18/24페이지)
번호 | 제목 | 글쓴이 | 조회 | 날짜 |
---|---|---|---|---|
마야 뷰포트 네비게이션 팁 | 푸딩뱃살 | 42776 | 2020.04.06 17:22 | |
Maya 버전 별 Python 버전 | 푸딩뱃살 | 64085 | 2014.01.08 17:59 | |
124 | [FX] Lesson 1: Creating nCloth collisions Step 2 | artsOne | 2163 | 2008.04.13 17:28 |
123 | [FX] Lesson 1: Creating nCloth collisions Step 1 | artsOne | 2403 | 2008.04.13 16:23 |
122 | [참고] Expression Manual | artsOne | 2243 | 2008.04.13 02:44 |
121 | [Script] MEL 기초 #01 - 기초 (자료형) | artsOne | 3959 | 2008.04.10 00:28 |
120 | [Base] 선택 우선순위 | artsone | 2169 | 2008.04.09 02:47 |
119 | [Script] Python for Maya - 10. polygon vertex random move | artsOne | 4619 | 2008.04.06 23:44 |
118 | [Rigging] Deform > Edit Membership Tool | artsone | 2635 | 2008.04.05 02:28 |
117 | [Rigging] Deform > Wire 활용 | artsone | 2242 | 2008.04.05 02:01 |
116 | [Animation] Bake Simulation | artsone | 1879 | 2008.04.01 23:04 |
115 | [Rigging] 로프 Stretch Rigging | artsone | 2380 | 2008.03.31 21:40 |
114 | [Rigging] Bouncing Ball Rigging | artsone | 2366 | 2008.03.20 23:29 |
113 | [Rigging] bind 후 object가 2배로 움직이는 현상 막기 | artsone | 2125 | 2008.03.08 03:28 |
112 | [Rigging] Lattice와 Rigid bind를 이용한 skinning | artsone | 2641 | 2008.03.08 03:18 |
111 | [Script] Python for Maya - 9. polysmooth 자동 설정 (format 변환) | artsOne | 4420 | 2008.03.05 01:18 |
110 | [Script] Python for Maya - 8. random 응용 (if문) | artsOne | 4732 | 2008.02.27 02:22 |
109 | [Script] Python for Maya - 7. random (for문) | artsone | 4755 | 2008.02.26 01:37 |
>> | [Script] Python for Maya - 6. 리스트 자료 다루기 2 | artsOne | 3836 | 2008.02.23 17:17 |
107 | [Script] Python for Maya - 5. 리스트 자료 다루기 1 | artsOne | 3924 | 2008.02.22 20:27 |
106 | [Script] Python for Maya - 4. set (집합) | artsOne | 4829 | 2008.02.22 17:49 |
105 | [Script] Python for Maya - 3. pickle (지속 모듈-파일 관리) | artsOne | 4806 | 2008.02.21 01:57 |