Python 特定の文字以降削除 複数

前提

下記のリストを特定の文字(’-’)以降削除したいですが、エラーが表示されます。
どのように修正すれば良いでしょうか。
お手数ですが、ご確認をお願い致します。

実現したいこと

リスト

txt = ['abc-def','abc-def']
txt = ['abc-def','abc-def'] list_new=abc,abc

エラー

raceback (most recent call last): File "test.py", line 16, in <module> list_new = txt.find('-') AttributeError: 'list' object has no attribute 'find'

該当のソースコード

txt = ['abc-def','abc-def'] for character in txt: list_new = txt.find('-') print(txt[:list_new])

コメントを投稿

0 コメント