n | """ | n | |
| Только поля класса | | |
| Написать класс Struct, элементы которого будут содержать поля, соответствующие всем | | |
| возможным четырёхбуквенным последовательностям из букв a, b, c и d (от aaaa до dddd). | | |
| Попытка обращения к полям с любыми другими именами (кроме начинающихся на «_») должна | | |
| приводить к исключению AttributeError. Записывать что-либо в объекты этого класса | | |
| не предполагается, но предполагается делать много его экземпляров. Необязательное | | |
| упражнение: уложить описание класса в одну строку (а с помощью itertools — вполне | | |
| компактную). Или хотя бы в две. | | |
| | | |
| Примеры | | |
| Входные данные | | |
| print(Struct().abba) | | |
| | | |
| Результат работы | | |
| abba | | |
| """ | | |
| from itertools import product | | from itertools import product |
n | from time import time | n | |
| | | |
| class Struct: | | class Struct: |
| __slots__ = [] | | __slots__ = [] |
n | | n | aaaa = 'aaaa' |
| | | aaab = 'aaab' |
| | | aaac = 'aaac' |
| | | aaad = 'aaad' |
| | | aaba = 'aaba' |
| | | aabb = 'aabb' |
| | | aabc = 'aabc' |
| | | aabd = 'aabd' |
| | | aaca = 'aaca' |
| | | aacb = 'aacb' |
| cddc = 'cddc' | | aacc = 'aacc' |
| | | aacd = 'aacd' |
| | | aada = 'aada' |
| | | aadb = 'aadb' |
| | | aadc = 'aadc' |
| | | aadd = 'aadd' |
| | | abaa = 'abaa' |
| | | abab = 'abab' |
| | | abac = 'abac' |
| | | abad = 'abad' |
| | | abba = 'abba' |
| | | abbb = 'abbb' |
| | | abbc = 'abbc' |
| | | abbd = 'abbd' |
| abca = 'abca' | | abca = 'abca' |
n | | n | abcb = 'abcb' |
| | | abcc = 'abcc' |
| | | abcd = 'abcd' |
| | | abda = 'abda' |
| | | abdb = 'abdb' |
| | | abdc = 'abdc' |
| | | abdd = 'abdd' |
| | | acaa = 'acaa' |
| | | acab = 'acab' |
| | | acac = 'acac' |
| | | acad = 'acad' |
| | | acba = 'acba' |
| | | acbb = 'acbb' |
| | | acbc = 'acbc' |
| | | acbd = 'acbd' |
| | | acca = 'acca' |
| | | accb = 'accb' |
| | | accc = 'accc' |
| | | accd = 'accd' |
| | | acda = 'acda' |
| | | acdb = 'acdb' |
| | | acdc = 'acdc' |
| | | acdd = 'acdd' |
| | | adaa = 'adaa' |
| | | adab = 'adab' |
| | | adac = 'adac' |
| | | adad = 'adad' |
| | | adba = 'adba' |
| | | adbb = 'adbb' |
| | | adbc = 'adbc' |
| | | adbd = 'adbd' |
| | | adca = 'adca' |
| | | adcb = 'adcb' |
| | | adcc = 'adcc' |
| | | adcd = 'adcd' |
| | | adda = 'adda' |
| | | addb = 'addb' |
| | | addc = 'addc' |
| | | addd = 'addd' |
| | | baaa = 'baaa' |
| | | baab = 'baab' |
| | | baac = 'baac' |
| | | baad = 'baad' |
| | | baba = 'baba' |
| | | babb = 'babb' |
| | | babc = 'babc' |
| | | babd = 'babd' |
| | | baca = 'baca' |
| | | bacb = 'bacb' |
| | | bacc = 'bacc' |
| | | bacd = 'bacd' |
| | | bada = 'bada' |
| | | badb = 'badb' |
| | | badc = 'badc' |
| | | badd = 'badd' |
| | | bbaa = 'bbaa' |
| | | bbab = 'bbab' |
| | | bbac = 'bbac' |
| | | bbad = 'bbad' |
| | | bbba = 'bbba' |
| | | bbbb = 'bbbb' |
| | | bbbc = 'bbbc' |
| | | bbbd = 'bbbd' |
| | | bbca = 'bbca' |
| | | bbcb = 'bbcb' |
| | | bbcc = 'bbcc' |
| | | bbcd = 'bbcd' |
| | | bbda = 'bbda' |
| | | bbdb = 'bbdb' |
| | | bbdc = 'bbdc' |
| | | bbdd = 'bbdd' |
| | | bcaa = 'bcaa' |
| | | bcab = 'bcab' |
| bcac = 'bcac' | | bcac = 'bcac' |
n | daba = 'daba' | n | bcad = 'bcad' |
| dbcb = 'dbcb' | | bcba = 'bcba' |
| | | bcbb = 'bcbb' |
| | | bcbc = 'bcbc' |
| | | bcbd = 'bcbd' |
| | | bcca = 'bcca' |
| | | bccb = 'bccb' |
| | | bccc = 'bccc' |
| | | bccd = 'bccd' |
| | | bcda = 'bcda' |
| | | bcdb = 'bcdb' |
| | | bcdc = 'bcdc' |
| | | bcdd = 'bcdd' |
| | | bdaa = 'bdaa' |
| | | bdab = 'bdab' |
| ddac = 'ddac' | | bdac = 'bdac' |
| | | bdad = 'bdad' |
| | | bdba = 'bdba' |
| | | bdbb = 'bdbb' |
| adbc = 'adbc' | | bdbc = 'bdbc' |
| | | bdbd = 'bdbd' |
| | | bdca = 'bdca' |
| | | bdcb = 'bdcb' |
| | | bdcc = 'bdcc' |
| | | bdcd = 'bdcd' |
| | | bdda = 'bdda' |
| | | bddb = 'bddb' |
| | | bddc = 'bddc' |
| | | bddd = 'bddd' |
| | | caaa = 'caaa' |
| caab = 'caab' | | caab = 'caab' |
n | bbcd = 'bbcd' | n | |
| ccca = 'ccca' | | |
| bdca = 'bdca' | | |
| ddda = 'ddda' | | |
| bdba = 'bdba' | | |
| dbba = 'dbba' | | |
| cdba = 'cdba' | | |
| cdcc = 'cdcc' | | |
| dddd = 'dddd' | | |
| dbbd = 'dbbd' | | |
| bcda = 'bcda' | | |
| aabc = 'aabc' | | |
| cbdc = 'cbdc' | | |
| dcaa = 'dcaa' | | |
| bcbb = 'bcbb' | | |
| ddaa = 'ddaa' | | |
| aabd = 'aabd' | | |
| bacd = 'bacd' | | |
| acbd = 'acbd' | | |
| bcbc = 'bcbc' | | |
| bddd = 'bddd' | | |
| aaba = 'aaba' | | |
| aada = 'aada' | | |
| bbbb = 'bbbb' | | |
| caca = 'caca' | | |
| cabd = 'cabd' | | |
| baad = 'baad' | | |
| adac = 'adac' | | |
| bdad = 'bdad' | | |
| bbdb = 'bbdb' | | |
| bdcd = 'bdcd' | | |
| badd = 'badd' | | |
| dcbb = 'dcbb' | | |
| cacd = 'cacd' | | |
| dbad = 'dbad' | | |
| accc = 'accc' | | |
| cccd = 'cccd' | | |
| cbdb = 'cbdb' | | |
| acdc = 'acdc' | | |
| cccb = 'cccb' | | |
| acaa = 'acaa' | | |
| cdcb = 'cdcb' | | |
| dacb = 'dacb' | | |
| bbdc = 'bbdc' | | |
| bcaa = 'bcaa' | | |
| bddb = 'bddb' | | |
| ccab = 'ccab' | | |
| accd = 'accd' | | |
| bdab = 'bdab' | | |
| bbbd = 'bbbd' | | |
| dbda = 'dbda' | | |
| baaa = 'baaa' | | |
| dacc = 'dacc' | | |
| cdab = 'cdab' | | |
| cadc = 'cadc' | | |
| addb = 'addb' | | |
| badc = 'badc' | | |
| bcbd = 'bcbd' | | |
| adad = 'adad' | | |
| bada = 'bada' | | |
| bcca = 'bcca' | | |
| cdca = 'cdca' | | |
| aaaa = 'aaaa' | | |
| abbb = 'abbb' | | |
| caac = 'caac' | | caac = 'caac' |
n | aaad = 'aaad' | n | caad = 'caad' |
| addd = 'addd' | | |
| acba = 'acba' | | |
| baca = 'baca' | | |
| bbdd = 'bbdd' | | |
| daad = 'daad' | | |
| dbdc = 'dbdc' | | |
| ddba = 'ddba' | | |
| adba = 'adba' | | |
| ccac = 'ccac' | | |
| bcdc = 'bcdc' | | |
| adab = 'adab' | | |
| abaa = 'abaa' | | |
| addc = 'addc' | | |
| babc = 'babc' | | |
| caba = 'caba' | | caba = 'caba' |
n | adcb = 'adcb' | n | |
| dbdd = 'dbdd' | | |
| cdbc = 'cdbc' | | |
| aadc = 'aadc' | | |
| bdbb = 'bdbb' | | |
| cccc = 'cccc' | | |
| dbdb = 'dbdb' | | |
| dcbc = 'dcbc' | | |
| ccdb = 'ccdb' | | |
| ddab = 'ddab' | | |
| abdd = 'abdd' | | |
| dcdd = 'dcdd' | | |
| adbd = 'adbd' | | |
| babd = 'babd' | | |
| adcc = 'adcc' | | |
| cadb = 'cadb' | | |
| abcc = 'abcc' | | |
| ddbc = 'ddbc' | | |
| cbaa = 'cbaa' | | |
| cbbb = 'cbbb' | | |
| cada = 'cada' | | |
| cbac = 'cbac' | | |
| dddb = 'dddb' | | |
| bbcc = 'bbcc' | | |
| badb = 'badb' | | |
| bbca = 'bbca' | | |
| daac = 'daac' | | |
| accb = 'accb' | | |
| dcad = 'dcad' | | |
| adaa = 'adaa' | | |
| acad = 'acad' | | |
| bcba = 'bcba' | | |
| dcba = 'dcba' | | |
| dabd = 'dabd' | | |
| dacd = 'dacd' | | |
| cbbd = 'cbbd' | | |
| bbba = 'bbba' | | |
| dcdb = 'dcdb' | | |
| cdaa = 'cdaa' | | |
| cdbd = 'cdbd' | | |
| dbcd = 'dbcd' | | |
| daaa = 'daaa' | | |
| dadc = 'dadc' | | |
| cdac = 'cdac' | | |
| cbbc = 'cbbc' | | |
| bbad = 'bbad' | | |
| dbaa = 'dbaa' | | |
| dccc = 'dccc' | | |
| caaa = 'caaa' | | |
| aaab = 'aaab' | | |
| dcca = 'dcca' | | |
| ccaa = 'ccaa' | | |
| bbab = 'bbab' | | |
| dcda = 'dcda' | | |
| ddcd = 'ddcd' | | |
| dbca = 'dbca' | | |
| dbbc = 'dbbc' | | |
| acca = 'acca' | | |
| aacd = 'aacd' | | |
| baac = 'baac' | | |
| ccad = 'ccad' | | |
| abac = 'abac' | | |
| ddcb = 'ddcb' | | |
| abda = 'abda' | | |
| dddc = 'dddc' | | |
| bdbd = 'bdbd' | | |
| caad = 'caad' | | |
| adcd = 'adcd' | | |
| ddad = 'ddad' | | |
| abdb = 'abdb' | | |
| cbdd = 'cbdd' | | |
| ccbc = 'ccbc' | | |
| cdcd = 'cdcd' | | |
| abba = 'abba' | | |
| acdd = 'acdd' | | |
| cddd = 'cddd' | | |
| cabb = 'cabb' | | cabb = 'cabb' |
| cabc = 'cabc' | | cabc = 'cabc' |
n | | n | cabd = 'cabd' |
| | | caca = 'caca' |
| | | cacb = 'cacb' |
| | | cacc = 'cacc' |
| abcd = 'abcd' | | cacd = 'cacd' |
| | | cada = 'cada' |
| | | cadb = 'cadb' |
| | | cadc = 'cadc' |
| aadd = 'aadd' | | cadd = 'cadd' |
| | | cbaa = 'cbaa' |
| | | cbab = 'cbab' |
| | | cbac = 'cbac' |
| | | cbad = 'cbad' |
| | | cbba = 'cbba' |
| | | cbbb = 'cbbb' |
| | | cbbc = 'cbbc' |
| | | cbbd = 'cbbd' |
| | | cbca = 'cbca' |
| | | cbcb = 'cbcb' |
| | | cbcc = 'cbcc' |
| | | cbcd = 'cbcd' |
| | | cbda = 'cbda' |
| | | cbdb = 'cbdb' |
| | | cbdc = 'cbdc' |
| | | cbdd = 'cbdd' |
| | | ccaa = 'ccaa' |
| | | ccab = 'ccab' |
| | | ccac = 'ccac' |
| | | ccad = 'ccad' |
| | | ccba = 'ccba' |
| | | ccbb = 'ccbb' |
| | | ccbc = 'ccbc' |
| | | ccbd = 'ccbd' |
| | | ccca = 'ccca' |
| | | cccb = 'cccb' |
| | | cccc = 'cccc' |
| | | cccd = 'cccd' |
| | | ccda = 'ccda' |
| | | ccdb = 'ccdb' |
| | | ccdc = 'ccdc' |
| | | ccdd = 'ccdd' |
| | | cdaa = 'cdaa' |
| | | cdab = 'cdab' |
| | | cdac = 'cdac' |
| | | cdad = 'cdad' |
| | | cdba = 'cdba' |
| | | cdbb = 'cdbb' |
| | | cdbc = 'cdbc' |
| | | cdbd = 'cdbd' |
| | | cdca = 'cdca' |
| | | cdcb = 'cdcb' |
| | | cdcc = 'cdcc' |
| | | cdcd = 'cdcd' |
| | | cdda = 'cdda' |
| | | cddb = 'cddb' |
| | | cddc = 'cddc' |
| | | cddd = 'cddd' |
| | | daaa = 'daaa' |
| | | daab = 'daab' |
| | | daac = 'daac' |
| | | daad = 'daad' |
| | | daba = 'daba' |
| | | dabb = 'dabb' |
| | | dabc = 'dabc' |
| | | dabd = 'dabd' |
| | | daca = 'daca' |
| | | dacb = 'dacb' |
| | | dacc = 'dacc' |
| | | dacd = 'dacd' |
| | | dada = 'dada' |
| | | dadb = 'dadb' |
| | | dadc = 'dadc' |
| | | dadd = 'dadd' |
| | | dbaa = 'dbaa' |
| dbab = 'dbab' | | dbab = 'dbab' |
n | aaac = 'aaac' | n | |
| dabc = 'dabc' | | |
| bccd = 'bccd' | | |
| dbac = 'dbac' | | dbac = 'dbac' |
n | | n | dbad = 'dbad' |
| | | dbba = 'dbba' |
| | | dbbb = 'dbbb' |
| | | dbbc = 'dbbc' |
| | | dbbd = 'dbbd' |
| | | dbca = 'dbca' |
| | | dbcb = 'dbcb' |
| dbcc = 'dbcc' | | dbcc = 'dbcc' |
n | abad = 'abad' | n | dbcd = 'dbcd' |
| cdda = 'cdda' | | dbda = 'dbda' |
| | | dbdb = 'dbdb' |
| | | dbdc = 'dbdc' |
| | | dbdd = 'dbdd' |
| | | dcaa = 'dcaa' |
| | | dcab = 'dcab' |
| cacc = 'cacc' | | dcac = 'dcac' |
| | | dcad = 'dcad' |
| | | dcba = 'dcba' |
| | | dcbb = 'dcbb' |
| | | dcbc = 'dcbc' |
| | | dcbd = 'dcbd' |
| bacc = 'bacc' | | dcca = 'dcca' |
| | | dccb = 'dccb' |
| | | dccc = 'dccc' |
| dccd = 'dccd' | | dccd = 'dccd' |
n | dcbd = 'dcbd' | n | dcda = 'dcda' |
| bccc = 'bccc' | | |
| ccbb = 'ccbb' | | |
| bcad = 'bcad' | | |
| cacb = 'cacb' | | |
| bdcb = 'bdcb' | | dcdb = 'dcdb' |
| | | dcdc = 'dcdc' |
| | | dcdd = 'dcdd' |
| bbda = 'bbda' | | ddaa = 'ddaa' |
| dcab = 'dcab' | | ddab = 'ddab' |
| cbda = 'cbda' | | ddac = 'ddac' |
| cbcb = 'cbcb' | | ddad = 'ddad' |
| | | ddba = 'ddba' |
| cdbb = 'cdbb' | | ddbb = 'ddbb' |
| | | ddbc = 'ddbc' |
| | | ddbd = 'ddbd' |
| ddca = 'ddca' | | ddca = 'ddca' |
n | dabb = 'dabb' | n | |
| adbb = 'adbb' | | |
| baba = 'baba' | | |
| bcab = 'bcab' | | |
| bacb = 'bacb' | | |
| bdbc = 'bdbc' | | |
| bccb = 'bccb' | | |
| ccda = 'ccda' | | |
| acbb = 'acbb' | | |
| aadb = 'aadb' | | |
| aacc = 'aacc' | | |
| bddc = 'bddc' | | ddcb = 'ddcb' |
| cbba = 'cbba' | | |
| bcdd = 'bcdd' | | |
| ccba = 'ccba' | | |
| aacb = 'aacb' | | |
| bbbc = 'bbbc' | | |
| babb = 'babb' | | |
| dada = 'dada' | | |
| dadd = 'dadd' | | |
| baab = 'baab' | | |
| acda = 'acda' | | |
| ccbd = 'ccbd' | | |
| abbd = 'abbd' | | |
| cbcc = 'cbcc' | | |
| dadb = 'dadb' | | |
| abbc = 'abbc' | | |
| dccb = 'dccb' | | |
| bdcc = 'bdcc' | | |
| adda = 'adda' | | |
| cbad = 'cbad' | | |
| bbac = 'bbac' | | |
| abdc = 'abdc' | | |
| adca = 'adca' | | |
| bbaa = 'bbaa' | | |
| bbcb = 'bbcb' | | |
| bdac = 'bdac' | | |
| abcb = 'abcb' | | |
| dbbb = 'dbbb' | | |
| acbc = 'acbc' | | |
| ddbd = 'ddbd' | | |
| ddcc = 'ddcc' | | ddcc = 'ddcc' |
t | dcac = 'dcac' | t | |
| cdad = 'cdad' | | |
| bcdb = 'bcdb' | | |
| cadd = 'cadd' | | |
| cbcd = 'cbcd' | | |
| ccdd = 'ccdd' | | |
| acac = 'acac' | | |
| cbab = 'cbab' | | |
| ccdc = 'ccdc' | | |
| daab = 'daab' | | |
| aabb = 'aabb' | | |
| daca = 'daca' | | |
| dcdc = 'dcdc' | | ddcd = 'ddcd' |
| aaca = 'aaca' | | |
| cddb = 'cddb' | | |
| cbca = 'cbca' | | |
| ddbb = 'ddbb' | | |
| acdb = 'acdb' | | |
| acab = 'acab' | | |
| bdaa = 'bdaa' | | |
| abab = 'abab' | | |
| bdda = 'bdda' | | ddda = 'ddda' |
| | | dddb = 'dddb' |
| | | dddc = 'dddc' |
| | | dddd = 'dddd' |