[英]Converting Python code to PHP
PHP中的以下Python代码是什么?
import sys
li = range(1,777);
def countFigure(li, n):
m = str(n);
return str(li).count(m);
# counting figures
for substr in range(1,10):
print substr, " ", countFigure(li, substr);
想要的777输出
1 258
2 258
3 258
4 258
5 258
6 258
7 231
8 147
9 147
自从我做过Python以来已经有一段时间了,但是我认为应该这样做。 如果您能弄清楚str(li)
看起来会有所帮助。
<?php
$li = implode('', range(1, 776));
function countFigure($li, $n)
{
return substr_count($li, $n);
}
// counting figures
foreach (range(1, 9) as $substr)
echo $substr, " ", countFigure($li, $substr), "\n";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.