Save
Upgrade to remove ads
Busy. Please wait.
Log in with Clever
or

show password
Forgot Password?

Don't have an account?  Sign up 
Sign up using Clever
or

Username is available taken
show password


Make sure to remember your password. If you forget it there is no way for StudyStack to send you a reset link. You would need to create a new account.
Your email address is only used to allow you to reset your password. See our Privacy Policy and Terms of Service.


Already a StudyStack user? Log In

Reset Password
Enter the associated with your account, and we'll email you a link to reset your password.
focusNode
Didn't know it?
click below
 
Knew it?
click below
Don't Know
Remaining cards (0)
Know
0:00
Embed Code - If you would like this activity on your web page, copy the script below and paste it into your web page.

  Normal Size     Small Size show me how

Programming #4

From all lessons in "Organizing Data"

QuestionAnswer
List Ordered, Resizable, Mutable, Allows duplicates. myList = [1, 2]
Setting list elements If the element exists in the list, it can be set using the assignment operator. Using an element in a list is just like using a variable
in / not in operator Takes an element and a list and returns True if the element can be found in the list and False otherwise. Not in performs the opposite. 30 in numList
Iterating through a list using a for loop for selectedFruit in fruit: print(selectedFruit)
Iterating through a list using a for loop and length for i in range(len(fruit)): selectedFruit = fruit[i]  |  print(selectedFruit)
+ Concatenate two lists. [1, 2] + [3, 4] gives you [1, 2, 3, 4]
* Repeats the elements of a list for a given number of times. [1, 2, 3]*3 gives you [1, 2, 3, 1, 2, 3, 1, 2, 3]
[] Used to extract an element that is positioned at a given index in the given list (ex. list[index]). Positive indexes start from the front with 0 being the first index. Negative indexes start from the back with -1 being the last index
[:] Allows the extraction of entire section of elements. [lower-bound: upper-bound]. Lower is inclusive, Upper is exclusive. Both bounds are optional. list[1:3] returns [b, c]. list[:2] returns [a, b]
[::] Slicing with a specified step (skip value). [lower-bound : upper-bound : step]. Step is the number of elements to be skipped plus 1. Can be negative, meaning case elements are extracted in reverse order. [1: 9: 2] gives you [20, 40, 60, 80]
append() Adds to the end of a list. name.append("Fred")
index() Returns the first index where that value is. name.index("Jill")
extend() Appends a list. name.extend(["Bob, "Jill"]) 
insert() Inserts at specified index. name.insert(0, "Mike")
pop() Remove element at index. name.pop(1)
remove() Removes first occurrence. name.remove("Bob")
sort() Sorts list alphanumerically. name.sort()
Set Unordered, No index, Fixed, no Duplicates, Resizable. fruit = {"apple", "banana"}
update(<collection>) Adds a collection to the set
Joining sets using union purchased = fruit1.union(fruit2)
Joining sets using update fruit1.update(fruit2)
Intersecting sets Get set of elements in first set that are also in second set. inBoth = fruit1.intersection(fruit2)
Updating a set with its intersection fruit1.intersection_update(fruit2)
Difference in sets Get set of elements from first that that is not in second set. unique = fruit1.difference(fruit2)
Updating a set with its differences fruit1.difference_update(fruit2)
Tuple Ordered, Fixed, allows Duplicates, not resizable. fruit = ("apple", "banana")
Updating a tuple Convert it to a list, modify it, then convert it back to a tuple
Unpacking a tuple Assigns each element to a corresponding variable. For example, a, b, c = ("apple", "banana", "cherry") assigns "apple" to a, "banana" to b, and "cherry" to c
index() Returns the first index where that value is. name.index("Jill")
count() Counts number of occurrences in the list. name.count("Mike")
Dictionaries Ordered, Resizable. Elements(called items) are made of a key and a value. Fixed key and mutable values. Keys are unique, values can be duplicates. person = { "person1" : "Bob", "person2" : "Jill"}
Accessing dictionary items Use key to access item's value. person[<key>] or person.get(<key>)
Get list of keys person.keys()
Get list of values person.values()
Change or add dictionary items person[<key>] = <value> OR person.update({<key> : <value>})
Dictionary for loops for value in person: print(value)
update({<key>: <value>}) Add or update an item
pop(<key>) Remove element at index. name.pop(1)
items() Returns a list of key values as tuples
Strings Ordered, Indexed, Fixed, Not resizable
split([separator]) Split string into list with separator
Characters Strings with one element (no dedicated type). Encoded using ASCII or Unicode
strip() Removes space from start and end
split(<separator>) Split string into tuple on first occurrence of separator
splitlines() Split string into list with new lines
replace(<old>, <new>) Replaces all occurrences of the substring <old> with <new> in a string
partition(<separator>) Split string into tuple on first occurrence of separator
Created by: jolly_n4
Popular Computers sets

 

 



Voices

Use these flashcards to help memorize information. Look at the large card and try to recall what is on the other side. Then click the card to flip it. If you knew the answer, click the green Know box. Otherwise, click the red Don't know box.

When you've placed seven or more cards in the Don't know box, click "retry" to try those cards again.

If you've accidentally put the card in the wrong box, just click on the card to take it out of the box.

You can also use your keyboard to move the cards as follows:

If you are logged in to your account, this website will remember which cards you know and don't know so that they are in the same box the next time you log in.

When you need a break, try one of the other activities listed below the flashcards like Matching, Snowman, or Hungry Bug. Although it may feel like you're playing a game, your brain is still making more connections with the information to help you out.

To see how well you know the information, try the Quiz or Test activity.

Pass complete!
"Know" box contains:
Time elapsed:
Retries:
restart all cards