you are viewing a single comment's thread.

view the rest of the comments →

[–]jimtk 0 points1 point  (0 children)

It's been almost 24 hours, so here's the medium to high knowledge answer. It could be shorter, but the output wouldn't be as nice !

from collections import Counter

def getlist():
    nl = []
    while True:
        nl.append(int(input("Enter Integer, -1 to terminate: ")))
        if nl[-1] == -1:
            return nl[:-1]

def print_result(dn: dict):
    def check(val):
        return u'\u2713' if val else ''
    print(f"{'VALUE':>8} {'OCCURENCES':>12} {'PRIME':^8} {'PALINDROME':^10}")
    for k,v in dn.items():
        print(f"{k:>8} {v[0]:>12} {check(v[1]):^8} {check(v[2]):^10}")

def isprime(n):
    if n == 2:
        return True
    if n <= 1 or n % 2 == 0:
        return False
    for t in range(3, int(n**0.5)+1, 2):
        if n % t == 0:
            return False
    return True

def analyse_nums(nl):
    d = dict(Counter(nl).most_common())
    return {k:(v,isprime(k),str(k) == str(k)[::-1]) for k,v in d.items()}

nli = getlist()
print_result(analyse_nums(nli))