解決済み: リスト python から複数の文字列を削除する

最終更新: 09/11/2023

問題は、リストから複数の文字列を削除する組み込み関数が Python にないことです。

I have a list of strings:
<code>list = ['a','b','c','d']
</code>
and I want to remove multiple strings from the list, for example: 
<code>remove_list = ['a', 'c']
</code>


A:

You can use <code>set.difference()</code>:  (If you don't mind the order of elements in your list)  (If you want to keep the order of elements in your list, then use <code>filter()</code>)   (If you want to keep only unique elements in your list, then use <code>set()</code>)   (If you want to remove all duplicates from your list, then use <code>list(set())</code>)   (If you want to remove all duplicates from your list and keep the order of elements as well, then use <code>[i for i in set(lst)]</code>) 

Python では、文字列は一連の文字です。 文字列は、テキスト、数値、またはその他の種類のデータを格納するために使用できます。

Python で文字列を作成するには、文字列コンストラクターを使用します。

文字列 = 「こんにちは」

XNUMX つの文字列を連結して文字列を作成することもできます。

文字列 = 「こんにちは」 + 「世界」

リスト

Python では、リストはアイテムのコレクションを格納できるデータ構造です。 リストは空にすることも、他のリストを含む任意のタイプのオブジェクトを含めることもできます。

Python でリストを作成するには、list() 関数を使用します。 リストの最初の項目にアクセスするには、index() 関数を使用します。 リストの最後の項目にアクセスするには、len() 関数を使用します。

リストの末尾に項目を追加するには、append() 関数を使用します。 リストの末尾からアイテムを削除するには、pop() 関数を使用します。

関連記事: