Not logged in
Talk
Contributions
Create account
Log in
Navigation
Main page
About
People
Publications
Teaching
Resources
Research Blog
Wiki Functions
Recent changes
Help
Licensing
Page
Discussion
Edit
View history
Editing
Community Data Science Course (Spring 2019)/Day 2 Lecture
(section)
From CommunityData
Jump to:
navigation
,
search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Lists === * purpose ** Stores things ''in order'' * initialization ** making a list called my list: <code>my_list = ["a", "b", "c"]</code> ** comma separated elements. in python they can be a mix of any kind of types ** <code>type(my_list)</code> * <tt>len()</tt> review * accessing elements ** indexing like my_list[0] ** indexing starts from the front and we ''start counting at 0'' ** we go from the end with negative numbers ** what happens if we try to move outside of the range? ('''error!'') * adding elements ** using the the <code>my_list.append()</code> function ** the <code>.append()</code> function is a special kind of function that lists know about ** compare to <code>print</code> which is a global function. * changing elements ** replacing elements like <code>my_list[0] = "foo"</code> * finding elements in list ** e.g., <code>"z" in my_list</code> * slicing lists ** the colon inside the [] is the ''slicing syntax'' ** e.g., <code>my_list[0:2]</code> is 0th up to, but not including, the 2nd ** e.g., <code>my_list[2:]</code> ** e.g., <code>my_list[:2]</code> ** e.g., <code>my_list[:]</code> * strings are like lists ** we can slice lists ** len() *** <code>len("")</code> length of the empty string * many other interesting functions for lists ** e.g., <code>min()</code> and <code>max()</code> ** e.g., create a list of names and sort it <code>names.sort()</code> ** search "python lists" in any search engine to see many more functions that list knows about.
Summary:
Please note that all contributions to CommunityData are considered to be released under the Attribution-Share Alike 3.0 Unported (see
CommunityData:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:
Cancel
Editing help
(opens in new window)
Tools
What links here
Related changes
Special pages
Page information