我有一个显示“--f = tt --i = 3 --s = 0”的字符串,我想抓住每个值。我试过了:
//when start a new game.
ArrayList<String> currentGameList = YourList.clone();
//when need next word.
String displayText = currentGameList.remove(randomIntInRestSize); //after called remove, you will get the object at list(index), and the object will be removed from the list.
有些事是错的。任何帮助都会很好。感谢
答案 0 :(得分:2)
您可以使用模块re
:
import re
command ="--f=tt --i=3 --s=0"
re.findall("--\w+=(\w+)", command)
>>> ['tt', '3', '0']
你可以使用map和lambda:
map(lambda x:x.split("=")[-1], command.split())
>>> ['tt', '3', '0']
您可以更好地了解argparse