A User定义为:
public class User {
private String email;
private String uid;
private List<Group> groups;
public User(String email, String uid) {
this.email = email;
this.uid = uid;
this.groups = new ArrayList<>();
}
public User() {}
public User(String email, String uid, ArrayList<Group> groups) {
this.email = email;
this.uid = uid;
this.groups = groups;
}
public String getEmail() {
return email;
}
public String getUid() {
return uid;
}
public List<Group> getGroups() {
return groups;
}
public void addGroup(Group group) { …Run Code Online (Sandbox Code Playgroud) wordsFreq = {}
words = []
while True:
inputWord = raw_input()
if (inputWord != ""):
words.append(inputWord)
else:
break
for word in words:
wordsFreq[word] = wordsFreq.get(word, 0) + 1
for word,freq in wordsFreq.items():
print word + " - " + str(freq)
Run Code Online (Sandbox Code Playgroud)
显然我的单词[]和for循环是多余的,但我没有进一步的解释,任何人都可以向我解释为什么它是多余的?
main :: IO ()
main = do
contents <- readFile "text.txt"
let database = (read contents :: [Film])
putStr "Please enter your username: "
userName <- getLine
menu database
where menu newDb = do putStrLn "\nPlease select an option:"
putStrLn "1: Display all films currently in the database"
putStrLn "2: Add a new film to the database"
putStrLn "3: Search for films by director"
putStrLn "5: Exit"
putStr "\nSelected option: "
option <- getLine
case option of
"1" -> putStrLn(formatDatabase …Run Code Online (Sandbox Code Playgroud) 我正在尝试对已从xml(rss)转换为json的新闻项列表进行排序.我希望在合并后可以按照日期顺序对它们进行排序,但我不确定实现它的最佳方法.
json响应如下:
{ "success":true,
"message":"",
"data":{
"title":"Feed Name",
"item":[{
"title":"test",
"pubdate":"Sun, 20 Oct 2013 21:36:42 GMT"}]
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将Film类型更改为数据类型,以便更容易订购和保存并加载到文件,我在使用正确的参数匹配函数时遇到问题,使用类型更容易.
type Rating = (String, Int)
--type Film = (String, String, Int, [Rating])
data Film = Film String String Int [Rating]
deriving (Show,Ord,Eq, Read)
testDatabase :: [Film]
testDatabase = []
testFilm = ("Test","Test",2012,[("Test",8),("Test",5)])
saveToFile :: IO ()
saveToFile = do
putStrLn "Enter the output filename: "
name <- getLine
writeFile name (show testDatabase)
putStrLn "Done"
loadFromFile :: IO ()
loadFromFile = do
putStrLn "Enter the input filename: "
name <- getLine
contents <- readFile name
let testDatabase = length contents …Run Code Online (Sandbox Code Playgroud) 我在阻止WebView在retainInstance设置为true的片段内时重新加载时遇到问题.
我试过的路线:
SaveInstanceState(由于retainInstance,不会在旋转时传递包)一个自定义包,保存在onSaveInstanceState上并在create中保存保留WebView引用并尝试将其添加回视图层次结构
必须有一个更简单的方法吗?
现在我有两种类型:
type Rating = (String, Int)
type Film = (String, String, Int, [Rating])
Run Code Online (Sandbox Code Playgroud)
我有一个包含此数据的文件:
"Blade Runner"
"Ridley Scott"
1982
("Amy",5), ("Bill",8), ("Ian",7), ("Kevin",9), ("Emma",4), ("Sam",7), ("Megan",4)
"The Fly"
"David Cronenberg"
1986
("Megan",4), ("Fred",7), ("Chris",5), ("Ian",0), ("Amy",6)
Run Code Online (Sandbox Code Playgroud)
我怎样才能查看将所有条目存储到FilmDatabase = [Film]之类的文件?