Skip to content

Added notebook and script for HW_2#10

Open
ibragimovaamina wants to merge 1 commit into
mainfrom
hw2_decor_iter
Open

Added notebook and script for HW_2#10
ibragimovaamina wants to merge 1 commit into
mainfrom
hw2_decor_iter

Conversation

@ibragimovaamina

Copy link
Copy Markdown
Owner

No description provided.

@krglkvrmn krglkvrmn left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Comment thread hw2_decor_iter/HW_2.py

class MyDict(dict):
def __iter__(self):
return zip(self.keys(), self.values())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Норм, но можно вот так

Suggested change
return zip(self.keys(), self.values())
return iter(self.items())

Comment thread hw2_decor_iter/HW_2.py
Comment on lines +73 to +82
def iter_append(iterator, item):
new_iterator = []
while True:
try:
elem = next(iterator)
new_iterator.append(elem)
except StopIteration:
new_iterator.append(item)
break
return new_iterator

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Suggested change
def iter_append(iterator, item):
new_iterator = []
while True:
try:
elem = next(iterator)
new_iterator.append(elem)
except StopIteration:
new_iterator.append(item)
break
return new_iterator
def iter_append(iterator, item):
yield from iterator
yield item

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Список это не итератор, а iterable

Comment thread hw2_decor_iter/HW_2.py
Comment on lines +110 to +123
def wrapper_MyString(func):
def inner_func(input_str):
result_str = func(input_str)
result_MyString = MyString(result_str)
return result_MyString
return inner_func


def wrapper_MySet(func):
def inner_func(*args):
result_set = func(*args)
result_MySet = MySet(result_set)
return result_MySet
return inner_func

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А почему не одной функцией? Что если у нас было бы 30 разных классов?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants