Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What's the best way to find all possible combinations of a numeric string in Python and compare them with a given string?

i’ve no idea how to resolve my problem. i ve a string like ‘0.0.0’ and i need to find all possible combinination, like ‘0.0.1’, ‘0.0.2’……. ‘9.9.9’ then compare with another string if is bigger or no.
no i’ve code like this

K = 1

    res = []
    for ele in version_string:

        if ele.isdigit():
            res.append(str(int(ele) + K))
            version_string = res
            version_string = ''.join(version_string)
        else:
            res.append(ele)

    print(str(version_string))

output

0.0
1.1
2.2
3.3
4.4
5.5
6.6

this code only increment every number by one but i need all combination.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

thanks

>Solution :

import itertools

for numstr in ('.'.join(map(str, p)) for p in itertools.product(range(10), repeat=3)):
    print(numstr)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading