Skip to content

코드정리 + collection모듈 사용해보기. #48

@YJ-AnthonyJo

Description

@YJ-AnthonyJo

namedtuple, userlist
userlist : 보다 쉬운 메소드 재정의 가능.(리스트의 메소드를 override하지 않고 접근 가능하기에)
namedtuple : attribute로 접근 가능. -> immutable, 사용x, 새 class생성.

# Python program to demonstrate
# userlist


from collections import UserList


# Creating a List where
# deletion is not allowed
class MyList(UserList):
	
	# Function to stop deletion
	# from List
	def remove(self, s = None):
		raise RuntimeError("Deletion not allowed")
		
	# Function to stop pop from
	# List
	def pop(self, s = None):
		raise RuntimeError("Deletion not allowed")
	
# Driver's code
L = MyList([1, 2, 3, 4])

print("Original List")

# Inserting to List"
L.append(5)
print("After Insertion")
print(L)

# Deleting From List
L.remove()

image
image

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions