def anagram_2d_array(self): """ This method is used to store prime anagram and prime number which are not anagram in matrix or 2d array. and print them accordingly """ prime_list = Utility.get_prime() # get prime numbers anagram_list = Utility.get_anagram_prime( ) # get anagram numbers which is prime also not_anagram = [] row = 10 column = 25 two_d_array = [[0 for j in range(column)] for i in range(row)] k = 0 index = 0 for i in prime_list: if anagram_list.__contains__( i) is not True: # if file not contains same element not_anagram.append(i) # append into not_anagram list for i in range(row): for j in range(column): if k < len(anagram_list): two_d_array[i][j] = anagram_list[ k] # add element of anagram list into array k += 1 if k >= len(anagram_list) and index < len(not_anagram): two_d_array[i][j] = not_anagram[ index] # add element of not_anagram list k += 1 # into same array after anagram_list index += 1 for i in range(row): for j in range(column): if two_d_array[i][j] != 0: print(two_d_array[i][j], end=" ") # print 2d array print()
def prime_number_2d_array(self): """ This method is used to store prime number in matrix or 2d array and print in proper order. """ prime_list = Utility.get_prime() # get prime number row = 10 column = 25 limit = 100 # create empty 2d array two_d_array = [[0 for loop in range(column)] for loop in range(row)] loop3 = 0 for loop1 in range(row): for loop2 in range(column): if loop3 < len(prime_list): if prime_list[ loop3] <= limit: # prime number check with the limit two_d_array[loop1][loop2] = prime_list[ loop3] # add number into array loop3 += 1 limit += 100 # increment limit by 100 for each iteration for loop4 in range(row): for loop5 in range(column): if two_d_array[loop4][loop5] != 0: print(two_d_array[loop4][loop5], end=" ") # display elements in 2d array format print()