473,287 Members | 1,616 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

TypeError: 'type' object is not subscriptable

1 Bit
Expand|Select|Wrap|Line Numbers
  1. def merge_and_swap(list1, list2):
  2.   list1=list1+list2
  3.  
  4.   list1.insert(0,list[-1])
  5.   list1.pop(4)
  6.  
  7.   list1.insert(1,list[4])
  8.   list1.pop(1)
  9.  
  10.   return list1
  11.  
  12. print(merge_and_swap([1,2,3], [5]))
  13.  
I took a Error line which is 'TypeError: 'type' object is not subscriptable. What's the matter on my code and how can I solve it? Please give me an answer.
Jan 23 '21 #1
3 7303
Rabbit
12,516 Expert Mod 8TB
You reference a non-existent list, you probably meant list2
Jan 23 '21 #2
Sage11
1 Bit
The issue is you typed
Expand|Select|Wrap|Line Numbers
  1. list[-1]
. list is a type. I think you mean
Expand|Select|Wrap|Line Numbers
  1. list1[-1]
Jan 31 '21 #3
The error is self-explanatory. You are trying to subscript an object which you think is a list or dict, but actually is None. This means that you tried to do:

None[something]

NoneType is the type of the None object which represents a lack of value, for example, a function that does not explicitly return a value will return None . You might have noticed that the method sort() that only modify the list have no return value printed – they return the default None. This is a design principle for all mutable data structures in Python. 'NoneType' object is not subscriptable is the one thrown by python when you use the square bracket notation object[key] where an object doesn't define the __getitem__ method . This is a design principle for all mutable data structures in Python.
Dec 14 '21 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Atul Kshirsagar | last post by:
Hello, I am using Python 2.3.2 with a C++ extention DLL in muti-threaded environment. 1. For each new thread I create a separate sub-interpreter. 2. Each thread executes multiple python...
2
by: Balaji | last post by:
Hello Everybody... I have a problem.. This is the code... -------------------------------------- class Stack: def __init__(self,expr): self.stackP=
5
by: Randall Parker | last post by:
Using Python 2.4.2 on Windows 2000 in SPE. Getting: TypeError: 'str' object is not callable on this line: TmpErrMsg1 = "State machine %s " (StateMachineName) In Winpdb 1.0.6 the...
9
by: k.retheesh | last post by:
Can anybody tell me why am I getting this error message while trying to print a part of a string. Is there a better approach for this... Traceback (most recent call last): File...
10
by: Charles Russell | last post by:
Why does this work from the python prompt, but fail from a script? How does one make it work from a script? #! /usr/bin/python import glob # following line works from python prompt; why not in...
33
by: christophertidy | last post by:
Hi I am new to Python and have recieved this error message when trying to instantiate an object from a class from another file within the same directory and wondered what I have done wrong. I...
1
by: Charles Fox | last post by:
Hi gys -- I am looking at Numpy but getting this error when I try to get array sizes. I'm using Ubuntu Edgy with standard repositories and scipy. Any ideas? Am I doing something wrong or is it...
1
by: mankeluvsit | last post by:
hey everyone, for reasons, i needed to grap information from steampowered.com from BeautifulSoup import BeautifulSoup from urllib import urlopen import re import codecs html_text =...
1
by: Gonzalo Gonza | last post by:
When I execute this code (if the number finishes in 2 returns true, else none) def asdf(n): n=str(m) elif m==2: return True I get the following Error: Traceback (most recent call...
1
by: sobincc | last post by:
i have a python code.. thelist = with open('rollernet.txt') as f: thelist = sorted(thelist, key=lambda line : line) other_list = initial_time = int(list)
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.