質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

1回答

1468閲覧

CheckiOのCompletely Emptyがわからないです

退会済みユーザー

退会済みユーザー

総合スコア0

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

1クリップ

投稿2018/05/01 13:45

編集2022/01/12 10:55

前提・実現したいこと

checkioというサイトで多次元のリストが空かどうかを調べる問題を出されました。
問題は以下の通りです
You need to figure if a wellfounded and wellsized iterable is completely empty.

An iterable x0 is wellfounded if there is no infinite sequence

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).
A wellfounded iterable is wellsized if it has only finitely many iterable elements, and all of them are wellsized.

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

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
Input: A wellfounded and wellsized iterable.

Output: A bool.

発生している問題・エラーメッセージ

今のコードだとうまく判別できないリストがあります
どう変えれば良いか教えていただきたいです

エラーメッセージ Your result:True Right result:False Fail:completely_empty([[],[1]])

該当のソースコード

ソースコード if len(val) ==0: return True else: try: for i in range(len(val)): if not val[i]: return True else: try: for m in range(len(val[i])): if not val[i][m]: return True else: return False except: return False except: return False

試したこと

おそらく下から4行目のreturn TrueによってTrueになってしまっているようなのですがどう変えれば良いかわかりません

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

LouiS0616

2018/05/01 14:34

他の入出力例はないのでしょうか?文章だけで機能の把握をするのはなかなか骨です。
guest

回答1

0

(あとで全体がわかれば この回答は削除依頼します)

回答ではないのですが、こちらに書かせていただきました。


まず問題英文の後半について

{'': '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
Input: A wellfounded and wellsized iterable.

とあります。ここの意味はどうとられておられますか?

それから

Python

1if len(val) ==0: 2 return True 3 else: 4 try: 5 6    ・・・

try:ではじまるエラー処理はすべて
この課題の回答の手がかりを得るデバッグ用でしょうか?

投稿2018/05/01 14:10

kawakawa2018

総合スコア1195

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問