Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Python, from the code below, take the data from the dictionary created (test_db_two) and create a .csv file or .txt file and list steps

In Python, from the code below, take the data from the dictionary created (test_db_two) and create a .csv file or .txt file and list steps to use it in exel file.

import pickle

def getAllCombinations(s, length): if length == 0: return [''] else: ret = [] for idx, c in enumerate(s): combos = getAllCombinations(s[0:idx] + s[idx+1:], length - 1) for i in range(len(combos)): combos[i] = c + combos[i] ret += combos return ret def getPermutations(s, ret, swapIdx = 0): if swapIdx == len(s): ret.append(int(''.join(s))) for i in range(swapIdx, len(s)): cpy = [c for c in s] cpy[swapIdx], cpy[i] = cpy[i], cpy[swapIdx] getPermutations(cpy, ret, swapIdx + 1) def getAllPermutations(i): s = str(i) allPerms = set() for i in range(len(s)): curCombos = getAllCombinations(s, i + 1) for combo in curCombos: ret = [] getPermutations(combo, ret) allPerms = allPerms.union(set(ret)) return list(allPerms) def isPrime(n): if n==2 or n==3: return True if n%2==0 or n<2: return False for i in range(3,int(n**0.5)+1,2): # only odd numbers if n%i==0: return False return True

def getNumPrimes(i): perms = getAllPermutations(i) numprimes = 0 for perm in perms: if (isPrime(perm)): numprimes += 1 return numprimes def find_maxPrimes(): max = 0 maxNum = 0 for i in range(1000, 10000): cur = getNumPrimes(i) if (max < cur): max = cur maxNum = i return (maxNum)

def make_dict(): # max = 0 # maxNum = 0 #Printing here directly Dict = {} for i in range(1000, 10000): Dict[i] = getNumPrimes(i) return Dict

def make_db(name): db = make_dict() pickle_temp = open(f'{name}', 'wb') pickle.dump(db,pickle_temp) pickle_temp.close() def open_db(name): with open(f'{name}', 'rb') as pickle_temp: db = pickle.load(pickle_temp) return db

make_db('test_db_two')

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Web Database Development Step By Step

Authors: Jim Buyens

1st Edition

0735609667, 978-0735609662

More Books

Students also viewed these Databases questions