Зависит от того, являетесь ли Вы после ключей или значений...
Из описания MSDN Dictionary(TKey, TValue)
Класса:
// When you use foreach to enumerate dictionary elements,
// the elements are retrieved as KeyValuePair objects.
Console.WriteLine();
foreach( KeyValuePair kvp in openWith )
{
Console.WriteLine("Key = {0}, Value = {1}",
kvp.Key, kvp.Value);
}
// To get the values alone, use the Values property.
Dictionary.ValueCollection valueColl =
openWith.Values;
// The elements of the ValueCollection are strongly typed
// with the type that was specified for dictionary values.
Console.WriteLine();
foreach( string s in valueColl )
{
Console.WriteLine("Value = {0}", s);
}
// To get the keys alone, use the Keys property.
Dictionary.KeyCollection keyColl =
openWith.Keys;
// The elements of the KeyCollection are strongly typed
// with the type that was specified for dictionary keys.
Console.WriteLine();
foreach( string s in keyColl )
{
Console.WriteLine("Key = {0}", s);
}
import struct
def getData():
data = []
for i in range( 0, 1024 ):
data.append( 0.25 * math.sin( math.radians( i ) ) )
return struct.pack('f'*len(data), *data)
На самом деле, самый простой способ - использовать модуль структуры . Он предназначен для преобразования объектов Python в "собственные" объекты типа C.
Рассмотрим, возможно, вместо этого:
d = [0.25 * math.sin(math.radians(i)) for i in range(0, 1024)]
Возможно, вам нужно сначала использовать пакет, например pickle, для сериализации данных.
import pickle
f1 = open("test.dat", "wb")
pickle.dump(d, f1)
f1.close()
Затем загрузить его обратно:
f2 = open("test.dat", "rb")
d2 = pickle.Unpickler(f2).load()
f2.close()
d2 == d
Возвращает True