src_list = range(10) print(src_list) target_list = [2,4,5] # 리스트를 enumerate 시켜 해당 값의 리스트상 index를 습득 for index, dept in enumerate(src_list): # 타겟 리스트에 있는 경우 if dept in target_list: # 값에 따라 다른 처리 if dept == 2: # 리스트의 값에 index 로 접근하여 값을 대입 src_list[index] = 11 elif dept == 4: src_list[index] = 22 elif dept == 5: src_list[index] = 33 print(src_list)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question