Given an integer k, I have programmed a way to take all partitions of k such that
(1) each partition has at most n entries (where n is also given)
(2) each partition does not have any repeated odd numbers.
I also categorized the list of these partitions in descending order. However, I am unable to append zeros to the end of any given partition in the list such that all the partitions are n-tuples.
# Define n and k
(k, n) = (10, 5)
# Find partitions of k of max length n, and put partitions in list B
B = Partitions(k, max_length=n).list()
# Extracts partitions with repeated odd components and creates a separate list for them, namely B_Repeated_Odds
B_Repeated_Odds = []
for i in range(0, len(B)):
for j in range(0, len(B[i])):
for l in range(0, len(B[i])):
if B[i][j]%2 == 1:
if B[i][l]%2 == 1:
if B[i][j] == B[i][l]:
if j != l:
B_Repeated_Odds.append(B[i])
# Remove duplicates from B_Repeated_Odds
B_Unique = uniq(B_Repeated_Odds)
# Remove unwanted partitions from original list B, and sort finalized list in descending order
Improper_Part = Set(B).difference(Set(B_Unique))
Proper_Part = sorted(Improper_Part, reverse=true)
for i in range(0, len(Proper_Part)):
while len(Proper_Part[i]) < n:
Proper_Part[i].append(0)
The aforementioned issue occurs in the last three lines of code, with an error message stating "Attribute Error: 'IntegerListsLex_with_category.element_class' object has no attribute 'append'."
My question specifically is how can I change the types of the partitions within the list Proper_Part from IntegerListsLex_with_category.element_class to list (or any other object where the append command is applicable)? Or if anyone sees a better approach, I'd love to hear it.