Skip to content

hw1#25

Open
Alexanderpublic wants to merge 5 commits into
kib-courses:masterfrom
Alexanderpublic:Alexanderpublic-HW1
Open

hw1#25
Alexanderpublic wants to merge 5 commits into
kib-courses:masterfrom
Alexanderpublic:Alexanderpublic-HW1

Conversation

@Alexanderpublic
Copy link
Copy Markdown

Новая версия, постарался полностью сделать все найденные методы

Я попытался добить до mutable sequence, но не понял что делать в ее магических методах.
@Alexanderpublic Alexanderpublic changed the title Alexanderpublic hw1 hw1 Mar 29, 2020
Comment thread lecture_2/HW1.ipynb
" return x\n",
" \n",
" def append(self,data):\n",
" if (('len' in dir(data)) or ('__len__' in dir(data))):\n",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Можно было бы сделать проверку isinstance(data, collections.abc.Sized)

Comment thread lecture_2/HW1.ipynb
" self.capacity+=1\n",
" \n",
" def insert(self, index, item):\n",
" if index!=0:\n",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Если индекс отрицательный?

Comment thread lecture_2/HW1.ipynb
" \n",
" def __iter__(self):\n",
" for i in range(len(self)):\n",
" yield self.arraylist[i]\n",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Сделай через свой итератор

Comment thread lecture_2/HW1.ipynb
" return False\n",
" \n",
" def __getitem__(self,index):\n",
" return self.arraylist[index]\n",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Поработай явным образом с slice-индексом.

Comment thread lecture_2/HW1.ipynb
" def __setitem__(self, index, value):\n",
" t = self.arraylist[:index]\n",
" v = array(self.typecode,[value])\n",
" t = t + v + self.arraylist[index + 1:]\n",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Если индекс равен >= текущей длины?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

И что будет при отрицательном

Comment thread lecture_2/HW1.ipynb
" \n",
" def __reversed__(self):\n",
" for i in range(len(self)-1,-1,-1):\n",
" yield self.arraylist[i]\n",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Свой итератор

Comment thread lecture_2/HW1.ipynb
" self.capacity += 1\n",
" \n",
" def extend(self, item):\n",
" self.arraylist=array(self.typecode,self.arraylist[:]+array(self.typecode,[item]))\n",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

extend обычно для добавления контейнеров используется

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