467,914 Members | 1,815 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,914 developers. It's quick & easy.

TypeError: 'type' object is not subscriptable

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
  • viewed: 1997
Share:
2 Replies
Rabbit
Expert Mod 8TB
You reference a non-existent list, you probably meant list2
Jan 23 '21 #2
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]
4 Weeks Ago #3

Post your reply

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

Similar topics

1 post views Thread by Atul Kshirsagar | last post: by
2 posts views Thread by Balaji | last post: by
5 posts views Thread by Randall Parker | last post: by
9 posts views Thread by k.retheesh | last post: by
10 posts views Thread by Charles Russell | last post: by
33 posts views Thread by christophertidy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.