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

Otway rees protocol implementation, I need server, client and trusted side ...

I need server, client and trusted side communicating and charging a service with that protocol (or needham shroeder)

Expressions and assignment, Expressions and assignment We can think of...

Expressions and assignment We can think of most computer programs as performing some sort of transformation on data.  Our code may get as input the exam scores of everyone in

Variables, Variables We cannot  go very far without variables. A variabl...

Variables We cannot  go very far without variables. A variable is a value related to a name that we can bind  to have a particular value  and  then  later use in an expression.

Three layer neural network to classify the two sets of 3-D d, 1. Use a thre...

1. Use a three layer neural network to classify the two sets of 3-D data set. You should generate 100 samples for each data set based on the following criteria: Data set 1: generat

Program requests password to display information of author, Write a program...

Write a program that requests a password after the author/program information is displayed. Make the password "hello". The program should then ask the user for their name: if the n

Top-down approach, what are the issues assciated with top-down analysis

what are the issues assciated with top-down analysis

Lists, simple program using list

simple program using list

Programming, We sell pdf''s from our site and pdfs can be ordered from the ...

We sell pdf''s from our site and pdfs can be ordered from the site by selecting a book, putting it in a shopping cart, then signing in with a password or as a guest, and then check

Data wrangling, http://www.expertsmind.com/questions/data-wrangling-3011642...

http://www.expertsmind.com/questions/data-wrangling-301164244.aspx

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