All Courses

getting error list is not callable. For removing an element from tuple, I'm converting tuple to list

By Sde221876@gmail.com, 3 months ago
  • Bookmark
0

How to solve this issue in python, list is not callable. For removing an element from tuple, I'm converting tuple to list

Python
Lists
Tuple
not callable
2 Answers
0
Hitendradixit18@gmail.com

Restart the Kernel

0
Goutamp777

You can't modify a tuple in place because it is an immutable data type in Python. If you want to remove an element from a tuple, you can convert it to a list, remove the element, and then convert it back to a tuple. However, you should avoid using the name "list" as a variable name, because it is the name of a built-in Python function.

Here is an example of how you can remove an element from a tuple by converting it to a list and then back to a tuple:

# initial tuple
t = (1, 2, 3, 4)


# convert tuple to list
l = list(t)


# remove element from list
l.remove(3)


# convert list back to tuple
t = tuple(l)


print(t)  # Output: (1, 2, 4)


Your Answer

Webinars

Live Masterclass on : "How Machine Get Trained in Machine Learning?"

Mar 30th (7:00 PM) 516 Registered
More webinars

Related Discussions

Running random forest algorithm with one variable

View More