How can I do the following in Python?
array = [0, 10, 20, 40] for (i = array.length() - 1; i >= 0; i--)
I need to have the elements of an array, but from the end to the beginning.
You can make use of the reversed function for this as:
reversed
>>> array=[0,10,20,40] >>> for i in reversed(array): ... print(i)
Note that reversed(...) does not return a list. You can get a reversed list using list(reversed(array)).
reversed(...)
list(reversed(array))
Given a list ["foo", "bar", "baz"] and an item in the list "bar", how do I get its index (1) in Python?
Consider the following: items = [] items.append("apple") items.append("orange") items.append("banana") # FAKE METHOD: items.amount() # Should return 3 How do I get the number of elements in the list items?
For example, if passed the following: a = [] How do I check to see if a is empty?