Lists, Python Programming

Assignment Help:

 

Python has  a built-in list data  structure that  is easy  to use  and  incredibly convenient.  So, for that point, you can say

>>> y = [1, 2, 3]

>>> y[0]

1

>>> y[2]

3

>>> y[-1]

3

>>> y[-2]

2

>>> len(y)

3

>>> y + [4]

[1, 2, 3, 4]

>>> [4] + y

[4, 1, 2, 3]

>>> [4,5,6] + y

[4, 5, 6, 1, 2, 3]

>>> y

[1, 2, 3]

 

A list is written using  square brackets, with  whole code separated by commas. You may get components out  by specifying the  index  of the  element you  want  in square brackets, but  note  that,  like for character or string, the indexing initiate with  0.  Note  that  you  can index  elements of a list starting from  the initial (or zeroth) one (by using integers), or initiating from the last one (by using negative integers). You can add elements to a list using '+', taking  advantage of Python operator overloading. Note that this method does not modify  the original list, but creates  a new one.

Another useful  thing  to know  about  lists is that  you can make  slices of them.  A part of a structure is sublist;  you may get the basic idea from examples.

 

>>> b = range(10)

>>> b

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

>>> b[1:]

[1, 2, 3, 4, 5, 6, 7, 8, 9]

>>> b[3:]

[3, 4, 5, 6, 7, 8, 9]

>>> b[:7]

[0, 1, 2, 3, 4, 5, 6]

>>> b[:-1]

[0, 1, 2, 3, 4, 5, 6, 7, 8]

>>> b[:-2]

[0, 1, 2, 3, 4, 5, 6, 7]

 


Related Discussions:- Lists

Van der waals equation of state, how to make a python programme for van der...

how to make a python programme for van der waals equation of state with surface discontinouty

List Assignment, Task This problem creates a list containing names. The li...

Task This problem creates a list containing names. The list of names will be printed, sorted, printed again in the new sorted order, written to a new output file, and searched. Ca

Problem, an array A[0..n-1] of nr red elements, nw white elements and nb bl...

an array A[0..n-1] of nr red elements, nw white elements and nb blue elements in random order such that 0 = nr,nw,nb = n and nr + nw + nb = n, and arranging them such that all reds

Perimeter of a polygon, Perimeter of a polygon Now, let's consider the...

Perimeter of a polygon Now, let's consider the problem of computing the length  of the perimeter of a polygon. The input is a structure of vertices,  encoded as a list of list

Python program, Write a program that asks the user to enter a number of sec...

Write a program that asks the user to enter a number of seconds. The responses of the program will vary depending on the length of seconds: • If the number of seconds is under 60

Program that shows the use of all 6 math functions, Write an algorithm for ...

Write an algorithm for a program that shows the use of all 6 math functions. Write, test, and debug the program using Python. SAMPLE OUTPUT (not including author/program infor

Structured assignment, Structured assignment Once  we have  tuples and...

Structured assignment Once  we have  tuples and lists, we may use  a nice trick  in assignment expression, based  on the packing and unpacking of tuples. >>> a, b, c = 1, 2

Lists, simple program using list

simple program using list

Foundation of programming, hi i want to make a assignmnt of foundation of p...

hi i want to make a assignmnt of foundation of programming which include 4 task. I just want to know how much will be the price for that

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd