i recently posted a question to do with my project because i encountered an error, that error was solved but it led to a new different error that i thought would be better off being asked in a new question
#if user wants a small map i.e. less than 27 nodes, the nodes will be named differently to if it is a large map
global array_type
#creates the list
node_list=[]
node_array=[]
#makes sure the user only inputs a valid number of nodes
def check_int(x):
while True:
try:
#checks if node is integer
int(x)
#checks if node is negative
if int(x)<1:
#if it is, then it changes it to'x'
x='x'
#this means that it is picked up as a value error and passed to the except
int(x)
#returns the number of nodes if it is valid
return(x)
except ValueError:
print('only a whole positive number of nodes')
x= input('how many nodes in your map? ')
node_no= input('how many nodes in your map? ')
node_no=check_int(node_no)
#if there are less than 27 nodes then they can be labled a, b, c...
if int(node_no) < 27:
#creates a list with all the nodes in
for i in range(int(node_no)):
node_list.append(chr(int(i)+65))
#these two next lines are what i used to solve my previous error
#-----------------------------------------------------------------------
node_list2[:]=node_list
node_array.append(node_list2 for i in range(int(node_no)))
#-----------------------------------------------------------------------
array_type=1
print('node list=' + str(node_list))
#if there are more than 26 nodes then they will be labled a1, a2, a3...
elif int(node_no) >26:
#creates a list with all the nodes in
for i in range(int(node_no)):
node_list.append('A' + str(i+1))
node_array.append(node_list)
array_type=2
print('node list=' + str(node_list))
#creates a 2d array
for i in range(len(node_list)):
for i2 in range(len(node_list)):
#unfortunately when i solved my previous error my code started messing up here
#---------------------------------------------------------------------
node_array[i][i2]=str(node_list[i])+str(node_list[i2])
#---------------------------------------------------------------------
print('node list='+str(node_list))
print('node array='+str(node_array))
the outcome i recieve for this should be: (3 as node_no)
[['AA', 'AB', 'AC'], ['BA', 'BB', 'BC'], ['CA', 'CB', 'CC']]
however before i chaned the code to use a generator i got this:
[['CA', 'CB', 'CC'], ['CA', 'CB', 'CC'], ['CA', 'CB', 'CC']]
upon doing my reserch i found i had to use a generator, but since i did impliment it, it now says "TypeError: 'generator' object does not support item assignment" and i dont know how to solve this, should i have used a different method to solve my last problem? or should i assign to the array in a different method?