Swapping of element with its neighboring element (Python) Does this code seems good or it can be improve (without any library)?
Elements swapping of a list with its neighboring element
alist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

lenofalist = len(alist)

index = 0
temp = 0
last_element = 0
if lenofalist % 2 != 0:

    last_element = alist.pop()
    lenofalist -= 1

    while index &lt; lenofalist:
        temp = alist[index+1]
        alist[index+1] = alist[index]
        alist[index] = temp
        index += 2

    alist.append(last_element)

else:
    while index &lt; lenofalist:
        temp = alist[index+1]
        alist[index+1] = alist[index]
        alist[index] = temp
        index += 2
Your code, while it works, has a lot of room for improvement.

Naming conventions

Python has a best practice guide for style and naming conventions called PEP 8. Your variable names generally follow the lines of this guide, but lenofalist should be called len_of_alist. 

Duplicate code

Your code has a lot of duplicate code. 5 lines out of 19 are copied and pasted, that's over 25%. It lowers readability and makes any change to your code harder, as it may have to be changed twice.

In your case, the if ... else construct can be avoided altogether by exiting the loop before the last element is reach if the length of the list is odd.

Use for loops

You use while loops. It works, but is not the best fit for your case. You have to initialize an index and increment it manually, which makes the code longer and more complicated than it needs to be. Also, using i instead of index for a loop counter is generally accepted, as it is very common.

for i in range(0, len_of_alist, 2):
    # your code here


is functionally the same as your while loops, while being more concise and readable.

Swapping elements

In Python, you can swap the values of two variables using the following construct:

a, b = b, a


Your way of using a temporary variable is more language agnostic, but the Python way is much cleaner.

Make your code a function

Let's imagine you want to swap neighboring elements of a list as part of a larger project. It would be far more convenient and clear having this code in a function and calling it where you need it instead of inserting your code snippet where needed.

If you are using Python 3.5 or higher, you can use a type hint to make sure your function is indeed working with a list.

Putting it all together

Here is my take on improving your code:

def swap_neighbors(alist: list):
    for i in range(0, len(alist)-1, 2):
        alist[i], alist[i + 1] = alist[i + 1], alist[i]


my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
swap_neighbors(my_list)


As a side effect, there are no variables that need to be declared ahead, cleaning up the code even further.