从波纹管文本文件中,将文本文件读取到python程序中,然后根据单词的首字母将所有单词分组。用字典的形式表示组。凝视字母是“键”,而所有以字母开头的单词都是“值”列表。
文本文件为:
<InputText @bind-Value="@TextProperty" @attributes="HandyFunction()" />
@code{
Dictionary<string,object> HandyFunction()
{
var handy = new Dictionary<string, object>();
if(MyModel.isAutoFocus) dict.Add("autofocus",true);
return handy;
}
}
答案 0 :(得分:0)
stream = open('file name', 'r')
str = ''
current = ' '
while current != '':
current = stream.read(50)
str += current
words = str.split(' ')
dict = {}
for w in words:
if not w[0] in dict:
dict[w[0]] = [w]
else:
dict[w[0]].append(w)
字典是 dict