reverse a list without built-in functions

0 votes
How to reverse a list in Python without using built-in functions?
Jul 31, 2019 in Python by Fata
• 1,050 points
10,730 views

1 answer to this question.

0 votes

You can do it in 2 ways:

  1. Using user-defined-functions
  2. Using [::-1] operator

Using user-defined-functions:

EXAMPLE:

def myfunc(a):
    rev_str = []
    for x in a:
        rev_str.insert(0, x)
    return rev_str
print(myfunc([1,2,3,4,5]))

OUTPUT:     

[5, 4, 3, 2, 1]
Using [::-1]:
EXAMPLE:
y=[1,2,3,4,5]
z=y[::-1]
print(z)
OUTPUT:  
[5, 4, 3, 2, 1]

answered Jul 31, 2019 by Wajiha
• 1,960 points

Related Questions In Python

+1 vote
4 answers

how to sort a list of numbers without using built-in functions like min, max or any other function?

Yes it is possible. You can refer ...READ MORE

answered Jun 27, 2019 in Python by Arvind
• 3,050 points
188,604 views
0 votes
1 answer

Is there a way to list out in-built variables and functions of Python?

The in-built variables and functions are defined ...READ MORE

answered May 14, 2019 in Python by Junaid
2,245 views
0 votes
1 answer
0 votes
1 answer

Traverse a list in reverse

for item in my_list[::-1]: ...READ MORE

answered May 23, 2018 in Python by Nietzsche's daemon
• 4,260 points
624 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,466 views
0 votes
1 answer
0 votes
1 answer

Slicing a list using a variable, in Python

Yes its possible. Use the following piece ...READ MORE

answered Jul 2, 2019 in Python by Wajiha
• 1,960 points
2,080 views
+1 vote
1 answer

Creating a range of dates in Python

Yes, you can do it as follows: import ...READ MORE

answered Jul 4, 2019 in Python by Wajiha
• 1,960 points
1,467 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP