我有两个名为"hosts"的文件(在不同的目录中)
我想用python比较它们,看看它们是否是IDENTICAL.如果它们不相同,我想在屏幕上打印差异.
到目前为止,我已经尝试过了
hosts0 = open(dst1 + "/hosts","r")
hosts1 = open(dst2 + "/hosts","r")
lines1 = hosts0.readlines()
for i,lines2 in enumerate(hosts1):
if lines2 != lines1[i]:
print "line ", i, " in hosts1 is different \n"
print lines2
else:
print "same"
Run Code Online (Sandbox Code Playgroud)
但是当我跑这个时,我得到了
File "./audit.py", line 34, in <module>
if lines2 != lines1[i]:
IndexError: list index out of range
Run Code Online (Sandbox Code Playgroud)
这意味着其中一个主机拥有比另一个更多的线路.有没有更好的方法来比较2个文件并报告差异?
有一个我用java编程的游戏.游戏很简单(参见下图).有4只鸟和1只幼虫.这是一个2人游戏(AI vs Human).
当比赛开始时,幼虫开始,然后一只鸟可以移动(任何一只),然后是幼虫等......
我已经实现了MiniMax(Alpha Beta Pruning),我使用了以下的evaluate()函数(启发式函数).
让我们给板上的每个方块提供以下数字.
因此,我们的评估功能将是
h(n)=幼虫的位置值 - 鸟的位置值1 - 鸟的位置值2 - 鸟的位置值3 - 鸟的位置值4
幼虫将尝试最大化启发式值,而鸟类将尝试最小化它
例:
但是,这是一个简单而天真的启发式方法.它不会以聪明的方式行事.我是AI的初学者,我想知道如何改进这个启发式功能?
什么是好的/知情的启发式?
artificial-intelligence heuristics evaluation-function minimax alpha-beta-pruning
我想使用正则表达式删除bash中的XML注释(awk,sed,grep ...)我已经查看了有关此问题的其他问题,但他们遗漏了一些东西.这是我的xml代码
<Table>
<!--
to be removed bla bla bla bla bla bl............
removeee
to be removeddddd
-->
<row>
<column name="example" value="1" ></column>
</row>
</Table>
Run Code Online (Sandbox Code Playgroud)
所以我正在比较2个xml文件,但我不希望比较考虑到评论.我这样做
diff file1.xml file2.xml | sed '/<!--/,/-->/d'
Run Code Online (Sandbox Code Playgroud)
但这只删除了<!--以及最后一行开头的行.它不会删除其间的所有行.
我有一个基类如下
protected BaseClasse()
{
this.myDic= new Dictionary<string, List<somethingThatWillChange>>();
}
protected Dictionary<string, List<somethingThatWillChange>> myDic{ get; set; }
Run Code Online (Sandbox Code Playgroud)
但是,这个类将有两个将继承它的类.其中一个继承类需要new Dictionary<string, List<Type1>>(),另一个需要new Dictionary<string, List<Type2>>().
Type1和Type2是类,Type1有7个字段(名称,年龄,时间,工作,汽车,工资,标题),Type2有3个字段(名称,年龄,时间).
所以在基类中,我想初始化或声明我的词典 new Dictionary<string, List<somethingGeneric>>()
然后在两个继承的类中,我想初始化或将其转换为适当的List<type1>和List<type2>
有没有办法做到这一点?
bash ×1
c# ×1
comparison ×1
dictionary ×1
file ×1
heuristics ×1
inheritance ×1
list ×1
minimax ×1
python ×1
regex ×1
xml ×1