I graduated last May with an AAS in Information Technology, but during my last semester was listed as disabled due to my injuries in the service. I try to spend an hour each day learning Python, and my latest challenge has hit me hard--I just can't find the answer, even after an hour of searching the web for reprieve.
I challenged myself to make three lists; one and two, then the third with the second in the first. But the trick is, I have to do it within the terminal utilizing $user@pc python3. Here is the code I wrote:
# create list1
# filename = dumb_list
dumb_list = [3,5,7,9]
# create list2
#listname = dumber_list
dumber_list = [2,4,6,8,10]
# create list1 + list2, where list2 is inside of list1
# merge list1 into list2? Uh? How?
# // will research after trying manual merge //
# listname = dumbest_list
dumbest_list = [3,5,7,9,[2,4,6,8,10]]
# list3 = [list1[list1_contents]][list2[list2_contents]]
# list output in terminal should be from [list_i][list_i_contents]
# since 6 lies in the middle, let's go with it to pull from list3,
# so in terminal after typing lists, dumbest_list[2][2] should work
dumbest_list[2][2]
# --- failure ---
# Line 21 above, dumbest_list[2][2], fails...
# error message: Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
# TypeError: 'int' object is not subscriptable
Looking at Python documentation, it should pull the 6 from dumber_list within dumb_list using the call dumbest_list[2][2]
. As you can see from my comments it does not. I have spent over an hour searching this and cannot understand what is happening. I even tried making each number a string, thinking the issue was number related, but the same error occurs. Whatever it is, I am not seeing it. None of the searches here help me see it. I am definitely missing something.
I tried using paramaters [2:][2:], too. Is the issue my list? Was typing it manually my failing? If so, I am unable to determine how to insert the list inside the other list. I can combine them into one list, but unable to insert it. I would list that code, too, but I overwrote it earlier. But if failed, too, and no searches there gave me reprieve either.
Can someone break this down to me? I want to understand it so I can document and read the python documentation and understand the do's and dont's involved with this.
And why the terminal? I dunno, it just felt like a fun way to test myself, so I won't change it. I wrote it out anyway, using Fedora 30 and Visual Studio Code 1.39.2. I also tried breaking it into simpler steps using Jupyter via Anaconda. I failed across the board.
i am root,
_rod