How to add element in Python to the end of list using list.insert?

There is a list, for example,

a=[1,2,3,4]

I can use

a.append(some_value)

to add element at the end of list, and

a.insert(exact_position, some_value)

to insert element on any other position in list but not at the end as

a.insert(-1, 5)

will return [1,2,3,5,4]. So how to add an element to the end of list using list.insert(position, value)?

Answers


You'll have to pass the new ordinal position to insert using len in this case:

In [62]:

a=[1,2,3,4]
a.insert(len(a),5)
a
Out[62]:
[1, 2, 3, 4, 5]

Need Your Help

Detect if value is number in MySQL

mysql sql where-clause

Is there a way to detect if a value is a number in a MySQL query? Such as

Possible to test Google social login locally?

oauth oauth-2.0 google-oauth google-login

I want to test the Google Social login system on my local machine. However when I create a new OAuth button: 'Create New Client ID' it requires me to fill in the Authorized redirect URI which needs...