본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 76

반응형

Q>

You need to figure if a wellfounded and wellsized iterable is completely empty.

(유망하고 잘 알려진 iterable이 완전히 비어 있는지 파악해야합니다.)

An iterable x0 is wellfounded if there is no infinite sequence

(무한 시퀀스가 ​​없다면 iterable x0을 잘 알고있다.)

x1,x2,x3... such that ... in x3 in x2 in x1 in x0 (where in is meant iteratively, x(n+1) will be encountered while iterating through xn).

(x1, x2, x3 ... 이와 같이 ... x0의 x1에서 x2의 x3 (x는 반복적으로 의미하며, xn을 반복하면서 x (n + 1)이 발생 함).)

A wellfounded iterable is wellsized if it has only finitely many iterable elements, and all of them are wellsized.

(wellfounded iterable은 유한 요소가 정교하게 많은 경우 잘 정의되며, 모두 잘 정의되어 있습니다. )

A wellfounded iterable is completely empty when all its elements are completely empty.

(wellfounded iterable은 모든 요소가 완전히 비어 있으면 완전히 비어 있습니다.)

Some consequences of the above definitions:

(위의 정의의 일부 결과는 다음과 같습니다.)

  • any empty iterable is completely empty
  • a non-iterable is never completely empty
  • the only wellfounded string is '', and it is completely empty
  • bytes, and (possibly nested) tuples/frozensets of them are always wellfounded and wellsized
  • {'': 'Nonempty'} is a wellfounded and completely empty iterable
  • after c=[];c.append(c), c is a non-wellfounded iterable
  • itertools.repeat(()) is wellfounded but not wellsized
  • itertools.repeat(5) is wellfounded and wellsized

빈 iterable은 완전히 비어 있습니다.

비 반복 가능은 결코 완전히 비어 있지 않습니다.

유일하게 잘 알려진 문자열은 ''이며 완전히 비어 있습니다.

바이트, 그리고 (아마도 중첩 된) 튜플 / 프리즈 세트는 항상 잘 정비되어 있으며 잘 알려져 있습니다

{ '': 'Nonempty'}는 잘 준비되어 있고 완전히 비어있는 반복 가능하다.

c = []; c.append (c) 이후에, c는 비 wellfounded 반복 가능 itertools.repeat (())는 wellfounded이지만 잘 정의되지 않았습니다.

itertools.repeat (5)는 잘 알려져 있으며 잘 정의되어 있습니다.

 

 

Input: A wellfounded and wellsized iterable.

Output: A bool.

Example:

completely_empty([]) == True
completely_empty([1]) == False
completely_empty([[]]) == True
completely_empty([[],[]]) == True
completely_empty([[[]]]) == True
completely_empty(['']) == True
completely_empty([[],[{'':'No WAY'}]]) == True

 

A>

def completely_empty(val):
    try:
        return all(map(completely_empty, val))
    except TypeError:
        return False

if __name__ == '__main__':
    #These "asserts" using only for self-checking and not necessary for auto-testing
    assert completely_empty([]) == True, "First"
    assert completely_empty([1]) == False, "Second"
    assert completely_empty([[]]) == True, "Third"
    assert completely_empty([[],[]]) == True, "Forth"
    assert completely_empty([[[]]]) == True, "Fifth"
    assert completely_empty([[],[1]]) == False, "Sixth"
    assert completely_empty([0]) == False, "[0]"
    assert completely_empty(['']) == True
    assert completely_empty([[],[{'':'No WAY'}]]) == True
    print('Done')

 

O>

Done

Process finished with exit code 0

 

S>

https://py.checkio.org/

반응형

'Python_Matter > Solve' 카테고리의 다른 글

Python Learn the basics Quiz 78  (0) 2019.06.20
Python Learn the basics Quiz 77  (0) 2019.06.20
Python Learn the basics Quiz 75  (0) 2019.06.20
Python Learn the basics Quiz 74  (0) 2019.06.20
Python Learn the basics Quiz 73  (0) 2019.06.19