SortedListオブジェクトのC#でのサイズが固定されているかどうかを確認します
SortedListオブジェクトのサイズが固定されているかどうかを確認するには、コードは次のとおりです-
例
using System;
using System.Collections;
public class Demo {
public static void Main(){
SortedList list = new SortedList();
list.Add("1", "One");
list.Add("2", "Two");
list.Add("3", "Three");
list.Add("4", "Four");
list.Add("5", "Five");
list.Add("6", "Six");
list.Add("7", "Seven");
list.Add("8", "Eight");
Console.WriteLine("Key and Value of SortedList....");
foreach(DictionaryEntry k in list )
Console.WriteLine("Key: {0}, Value: {1}", k.Key , k.Value );
Console.WriteLine("Is the SortedList having the value? "+list.ContainsValue("Three"));
Console.WriteLine("The SortedList object has a fixed size? = "+list.IsFixedSize);
}
} 出力
これにより、次の出力が生成されます-
Key and Value of SortedList.... Key: 1, Value: One Key: 2, Value: Two Key: 3, Value: Three Key: 4, Value: Four Key: 5, Value: Five Key: 6, Value: Six Key: 7, Value: Seven Key: 8, Value: Eight Is the SortedList having the value? True The SortedList object has a fixed size? = False
例
別の例を見てみましょう-
using System;
using System.Collections;
public class Demo {
public static void Main(){
SortedList list = new SortedList();
list.Add("1", "John");
list.Add("2", "Tim");
list.Add("3", "Karl");
list.Add("4", "Gary");
list.Add("5", "Katie");
Console.WriteLine("Key and Value of SortedList....");
foreach(DictionaryEntry k in list )
Console.WriteLine("Key: {0}, Value: {1}", k.Key , k.Value );
Console.WriteLine("The SortedList object has a fixed size? = "+list.IsFixedSize);
}
} 出力
これにより、次の出力が生成されます-
Key and Value of SortedList.... Key: 1, Value: John Key: 2, Value: Tim Key: 3, Value: Karl Key: 4, Value: Gary Key: 5, Value: Katie The SortedList object has a fixed size? = False
-
Python –Kキーに対応する特定の値が存在するかどうかを確認します
キー「K」に対応する特定の値が存在するかどうかを確認する必要がある場合は、リスト内包表記が使用されます。 以下は同じのデモンストレーションです- 例 my_list = [{"python" : "14", "is" : "great", "fun" : "1`"},{"python" : "cool", "is" : "fun", "best" : "81&quo
-
PythonでタプルにNone値があるかどうかを確認します
タプルに「None」値があるかどうかを確認する必要がある場合は、「any」メソッド、「map」メソッド、およびラムダ関数を使用できます。 map関数は、特定の関数/操作を反復可能オブジェクト(リスト、タプルなど)のすべてのアイテムに適用します。結果としてリストを返します。 匿名関数は、名前なしで定義される関数です。 一般に、Pythonの関数は「def」キーワードを使用して定義されますが、無名関数は「lambda」キーワードを使用して定義されます。単一の式を取りますが、任意の数の引数を取ることができます。式を使用して、その結果を返します。 anyメソッドは、少なくとも1つのTrue値が