room = []
room.append({'number': 1, 'content': ""})
## room = [{'number': 1, 'content': ""}]
roomnumber = 1
## you should actually change this to 0. Otherwise you will get an "index out
## of range" error (see comment below)
inv = ["sword"]
command = input(": ")
first_letter = command(0)
if first_letter == "D":
item = command.split(" ", 2)
## why are you adding a max split here??
item.remove("D")
for i in range(0, len(inv)):
## equals for i in range(0, 5):, so iterates 0,1,2,3,4
## you forgot to add a closing bracket for the range
inv.pop(i)
## what are you trying to do here? This looks strange to me, given that after each
## pop, the value of your inv will be shortened..?
#this doesn't work
room[roomnumber]['content'].append(item[0])
## this does not work because your room list only contains one element, a
## dictionary, at index position 0. Probably THIS is your biggest issue here.
## Second, you're trying to change the value of 'content'. To change the value of a
## dictionarie's key, you need to use "=", and not ".append", as ".append" is used
## to append an element at the end of a list, to a list, and not to a dictionary.
## So, use room[roomnumber]['content'] = item[0]
item.pop(0)
Из того, что я понял, вы хотите добавить контент, в зависимости от номера комнаты, к значению контента словаря соответствующего номера комнаты. В этом случае весь ваш синтаксис неверен, и вы должны использовать:
room = []
room.append({1:""})
## and then, after the rest of the code:
room[roomnumber-1][roomnumber] = item[0]
или, что еще проще, учитывая, что одновременное использование списков и словарей здесь фактически устарело
## initiate one dictionary, containing all the rooms in key = roomnumber
## value = content pairs
rooms = {}
## the syntax to add a new room number with a new content into the dictionary
## would then simply be: rooms[number] = content, e.g.:
rooms[1] = ""
## to then set the value of the content for a given roomnumber, you simply use
rooms[roomnumber] = item[0]
Я рекомендую вам узнать о базовых c различиях между списками и словарями в python, вам, кажется, не хватает базового c понимания того, как элементы списков и словарей доступны / изменены (без обид конечно )