Shared Flashcard Set

Details

Week 7
programming principles
13
Computer Science
Post-Graduate
11/09/2017

Additional Computer Science Flashcards

 


 

Cards

Term
What happens if you multiply a string in Python, e.g. "'ABC' * 3"?
Definition
ABCABCABC
Term
2.Name and present an example of two string methods used to test the content of a string.
Definition
isupper()
islower()
isalpha()
isdigit()
Term
3.Name and present an example of two string methods used to search the content of a string.
Definition
"in" comparison operator

startswith('sub')
endswith('sub')
count('sub')
Term
4.Name and present an example of two string methods used to manipulate the content of a string.
Definition
lower()
upper()
strip()
Term
5.Write one line of Python code which turns a string into uppercase and strips whitespace from both ends.
Definition
string = myString.upper().strip()
Term
6.What are some of the names that dictionaries are known by in other languages?
Definition
associative arrays
hash tables
maps
Term
7.How do dictionaries differ from lists?
Definition
- items in a list identified by order index
-items in dictionary are arranged by key which is not ordered
(key is a label or name and has an associated value (key-value pair). Usually a string
Term
8.What happens if you try to refer to a key that does not exist in a dictionary?
Definition
Raise a KeyError
Term
9.Name and present an example of two dictionary methods.
Definition
key() - return list of all keys in dictionary
values() - return list of all values in dictionary
items() - list of tuples of all key-value pairs in dictionary
clear() -removes all items from dictionary
Term
10.What is a set, and how does it differ from a list and a dictionary?
Definition
a data structure that contains an unordered and unindexed collection of unique values, similar to mathematical concept of a set

No key (dictionary) and no index (list)
Term
11.What does the union of two sets contain, and what does the intersection of two sets contain?
Definition
combines both and keeps unique values

set A{1,2,3,4} set B {2,4,6,8}
Union = {1,2,3,4,6,8}

Intersection = {2,4}
Term
12.Show with examples how curly braces ("{" and "}") can be used to create both dictionaries and sets.
Definition
Curly brackets will create a set if you don't specify keys, and a dictionary if you do.

set1{'rock,'scissors','paper'}
dictionary1{'Rachel':'rock', 'Kim':'scissors', 'Jay':'paper'}
Term
13.Why are sets not supported in many languages?
Definition
only useful in fairly specific situations and most of their functionality can be achieved using other data structures
Supporting users have an ad free experience!