회원 로그인
정보기억 정보기억에 체크할 경우 다음접속시 아이디와 패스워드를 입력하지 않으셔도 됩니다.
그러나, 개인PC가 아닐 경우 타인이 로그인할 수 있습니다.
PC를 여러사람이 사용하는 공공장소에서는 체크하지 마세요.
소셜네트워크 서비스를 통해서 로그인하시면 별도의 로그인 절차없이 회원서비스를 이용하실 수 있습니다.


최근 게시물

1.노션에서 작성 중

1.노션에서 작성 중

개편하기 전까지 노션에서 작성 중

2024.04.04//read more

2.ChatGPT

2.ChatGPT

OpenAI로 대규모 언어 모델대화형...

2023.03.16//read more

3.노코딩 게임 엔진 - 빌..

3.노코딩 게임 엔진 - 빌..

빌드 지원안드로이드iOS윈도우즈특이사...

2023.03.14//read more

4.(완료) 미접속 회원 정..

4.(완료) 미접속 회원 정..

[완료] 36명의 회원을 정리하였습니...

2023.02.16//read more

5.매뉴얼 플러스 - 전자제..



안정적인 DNS 서비스 DNSEver
DNS Powered by DNSEver.com


Python for Maya - 6. 리스트 자료 다루기 2

artsOne | 2008.02.23 17:17 | 조회 3906

Digital Dream ( http://cafe.naver.com/digitaldream ) 카페의 'Maya Python 시작하기'의
기반으로 복습하는 차원에서 재정리한 것입니다.



이번엔 리스트의 자료 추가, 삭제, 운용에 대해서 알아보겠다.
이 모든 작업은 저장된 리스트를 추가 및 삭제를 하게 되면 실 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

466개(1/24페이지)
마야
번호 제목 글쓴이 조회 날짜
공지 마야 뷰포트 네비게이션 팁 푸딩뱃살 48335 2020.04.06 17:22
공지 Maya 버전 별 Python 버전 푸딩뱃살 68473 2014.01.08 17:59
464 [Dev] Autodesk Maya Devkit 다운로드 첨부파일 푸딩뱃살 788 2023.01.28 14:28
463 [Base] (해결 중) modules 환경설정 중 푸딩뱃살 705 2022.11.09 11:47
462 [Script] pymel 딕셔너리형 사용 시 KeyError 푸딩뱃살 975 2022.11.07 12:08
461 [오류] Building Numpy for Maya Python 2.7.x 푸딩뱃살 654 2022.10.23 14:38
460 [Base] 뷰포트에서 조절자가 안 보일때 첨부파일 푸딩뱃살 865 2022.10.13 15:47
459 [Rigging] mirror joints 사용 시 유의 사항 푸딩뱃살 863 2022.10.04 10:46
458 [Script] 2022에서 enum34 모듈 설치 금지 첨부파일 푸딩뱃살 642 2022.08.17 18:08
457 [Script] pymel 예제 푸딩뱃살 658 2022.07.05 19:20
456 [Script] 인코드 / 디코드 - 2.7 한글 사용 푸딩뱃살 951 2022.03.08 17:52
455 [Dev] ui 없이 mayapy로 자동화 첨부파일 푸딩뱃살 758 2022.02.17 13:56
454 [Dev] mayapy로 ui파일 py로 푸딩뱃살 559 2022.02.15 18:20
453 [오류] Error : MayaBonusTools 푸딩뱃살 988 2022.01.21 17:52
452 [오류] Error: ModuleNotFoundError 푸딩뱃살 828 2022.01.21 16:24
451 [Dev] mayapy 첨부파일 푸딩뱃살 711 2022.01.19 20:08
450 [Base] function selCom at 0x7f29c5c04aa0 첨부파일 푸딩뱃살 671 2022.01.19 17:24
449 [Base] wireframe on shaded 단축키 만들기 첨부파일 푸딩뱃살 973 2022.01.04 10:55
448 [오류] OpenCL Error 푸딩뱃살 551 2021.12.28 01:40
447 [Script] Easily Translate MEL Commands to Python 첨부파일 푸딩뱃살 920 2021.12.02 11:22
446 [Base] output window 띄우지 않기 첨부파일 푸딩뱃살 890 2021.11.24 21:44
445 [Rigging] shapeEditorManager 삭제 안됨 푸딩뱃살 961 2021.11.12 23:30