public sealed class Singleton { Singleton() {} public static Singleton Instance { get { return Nested.instance; } } class Nested { // Explicit static constructor to tell C# compiler // not to mark type as beforefieldinit static Nested() {} internal static readonly Singleton instance = new Singleton(); } } 現在のアプリケーションにJon …
値がリストである辞書を作成したい。例えば: { 1: ['1'], 2: ['1','2'], 3: ['2'] } 私が行った場合: d = dict() a = ['1', '2'] for i in a: for j in range(int(i), int(i) + 2): d[j].append(i) d [...]はリストではないため、KeyErrorが発生します。この場合、辞書を初期化するためにaを割り当てた後に次のコードを追加できます。 for x in range(1, 4): d[x] = list() これを行うより良い方法はありますか?2番目のforループに入るまで、必要になるキーがわからないとしましょう。例えば: class relation: scope_list = list() ... d = dict() for …