Concatenate list to int python

In this article, you will learn how to solve TypeError:can only concatenate list (not int) to list Python error.

Lets look at a code example that produces the same error.

fruits = ["mango and orange", "pineapple", "grapes and black grapes", "banana"] buy_price = [100, 200, 300, 400] fruits_bought = [] for s in range(0, len(fruits)): if buy_price[s] > 100: fruits_bought = fruits_bought + s for o in fruits_bought: print(fruits[o])

Output

Traceback (most recent call last): File "<string>", line 6, in <module> TypeError: can only concatenate list (not "int") to list

In order to solve TypeError:can only concatenate list (not int) to list Python error you have to use theappend()method to add an item to your list. consider the example below:

fruits = ["mango and orange", "pineapple", "grapes and black grapes", "banana"] buy_price = [100, 200, 300, 400] fruits_bought = [] for s in range(0, len(fruits)): if buy_price[s] > 100: fruits_bought.append(s) for o in fruits_bought: print(fruits[o])

output

pineapple grapes and black grapes banana

Related Articles

  • Create a Sleek Note app With Flutter
  • Building an eCommerce app with Flutter
  • Fix TypeError: only length-1 arrays can be
  • Solved typeerror: int object is not subscriptable
  • How to concatenate strings in golang?
  • Create A Password Strength Calculator using Kotlin
  • How To Convert Python String to Int and Int to String
  • Solved- python unsupported operand type
  • How to fix typeerror: $ is not a function in JavaScript
  • Build a CRUD application in Golang with PostgreSQL
  • Solved only integer scalar arrays can be converted
  • Build a CRUD Application with Hasura and Vue-Apollo
  • How to solve typeerror: list indices must be
  • Build a Gender/Age prediction Application with React
  • Solved typeerror: a bytes-like object is required,
  • Build a Note Taking Application using Kotlin
  • How to Concatenate Strings in PHP
  • Build a Signature Capture Application Using Canvas & Kotlin
  • Top 15 JavaScript machine learning libraries
  • Building a blogging platform Using React, GraphQL,