

By doing li2:4 you get a list containing the third and fourth element (i.e. In this tutorial, we will learn about the Python sort() method with the. You can also slice the list and iterate over the lists instead. Using the reverse() method we can reverse the contents of the list object in-place i.e., we don’t need to create a new list instead we just copy the existing elements to the original list in reverse order. for i in 2, 3: print(lii) Note that indexes start at zero, so if you want to get the 3 and 4 you will need to access list indexes 2 and 3. If len(contacts) = 0: #Empty list #Print error message here return else: i = 1 #For printing the "1. Method 2: Using the reverse() built-in function. For the list command, use the following code:.To print a Python list or nested lists line by line, we can use for loop to iterate over the lists of the list. For the view and del commands, display an error message if theuser enters an invalid contact number (number len(contacts)). For loop to Print lists of list in Python.Note that the first index of the 2-dimensional list is 0, butthe first contact starts with 1. There are a few useful tips to convert a Python list (or any other iterable such as a tuple) to a.Provide starting data for the following contacts: Use a list of lists (2-dimensional list) to store the data forthe contacts.Your program should have the following functions:.Eric IdleĬommand: view Number: 2 Name: Eric Idle Email: Phone: +44 20 7946 0958Ĭommand: add Name: Mike Murach Email: Phone: 55 Mike Murach was added.Ĭommand: del Number: 1 Guido van Rossum was deleted.Ĭommand: list 1.

COMMAND MENU list - Display all contacts view - View a contact add - Add a contact del - Delete a contact exit - Exit programĬommand: list 1.
