エントリーの編集
![loading...](https://b.st-hatena.com/bdefb8944296a0957e54cebcfefc25c4dcff9f5f/images/v4/public/common/loading@2x.gif)
エントリーの編集は全ユーザーに共通の機能です。
必ずガイドラインを一読の上ご利用ください。
mypy で Iterable[Optional[type]] から Iterable[type] を導出したい
記事へのコメント0件
- 注目コメント
- 新着コメント
このエントリーにコメントしてみましょう。
注目コメント算出アルゴリズムの一部にLINEヤフー株式会社の「建設的コメント順位付けモデルAPI」を使用しています
![アプリのスクリーンショット](https://b.st-hatena.com/bdefb8944296a0957e54cebcfefc25c4dcff9f5f/images/v4/public/entry/app-screenshot.png)
- バナー広告なし
- ミュート機能あり
- ダークモード搭載
関連記事
mypy で Iterable[Optional[type]] から Iterable[type] を導出したい
地道な方法 地道に下の通り書くと型チェックを通りました。 def remove_none_iterator(it: Iterator[Opt... 地道な方法 地道に下の通り書くと型チェックを通りました。 def remove_none_iterator(it: Iterator[Optional[int]]) -> Iterator[int]: while True: try: elem = next(it) while elem is None: elem = next(it) yield elem except StopIteration: return def remove_none(iterable: Iterable[Optional[int]]) -> Iterable[int]: it = iter(iterable) return remove_none_iterator(it) ただしこれだと返り値が必ずイテレーターになってしまいます。しかしそもそも filter() 関数は iterable を受け取ってイテレー