0

What is the following Python code in PHP?

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);

Wanted output for 777

1   258
2   258
3   258
4   258
5   258
6   258
7   231
8   147
9   147

1 Answer 1

1

It's been a while since I did any Python but I think this should do it. If you could clarify what str(li) looks like it would help.

<?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";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.