Unit 11 : Data Collection Flashcards
(31 cards)
What does rstrip() does?
- Remove the white space at right side
What does find() does?
- Find the string inside a file
What allows duplicate data, ordered and changeable?
- List
mylist = [1,2,3]
- Arrary , the order [0]
What allows duplicate data, ordered and unchangeable?
- Tuple
mytuple = ( “Adam”,”bob”)
What doesn’t allow duplicate data, unordered, unchangeable and unindexed?
- Set
myset = { “Dan” , “Chris”}
What doesn’t allow duplicate data, ordered and changeable?
- Dictionary
mydict = {
“name” : “Adam” ,
“password” : “123” ,
“role” : “chef”
}
print(mydict[“password”])
What is list used for?
- Group similar items
- Ordered, changeable and allow duplicate values
What is list defined by?
- Square brackets [ ]
How can we create list ? ( 4 )
- new_list = []
- new_list = [ 3, 4, 5, 6 ]
- new_list = list(range(10))
- new_list = list(range(2,7))
How can we add element? ( 2 )
- new_list[3] = 145
- new_list.append(3)
Can list insert different types of data ? ( newlist = [ 1 , “Adam” ] )
- Yes
How to add another list ? ( 2 )
- new_list[2] = new_list2
- newlist,append(new_list[2])
How to print out the list?
- print(new_list)
How to print the exact list?
- print(new_list[2])
How to print the list range?
- print(new_list[0:3])
- This will take the value in list between 0 , 1 , 2
How to scan through the lists?
new_list = [ 3, 4, 5, 6 ]
for i in new_list:
print(i)
- This can print the values inside the list without []
How to search for an element?
new_list = [ 3 , 4 , 5 , 6 ]
for i in new_list:
if ( i == 4 ):
print(f”{ i } found in list”)
new_list = [“John” , “Cat”]
name = str(input(“Enter a name to search for : “))
for i in new_list:
if ( i == name ):
print(f”{ i } found in list”)
What does append do?
- Add an element at the end
What does insert(0,200) do?
- Insert at position 0 the element 200
What does len(list_name) do?
- Return the length
What does min(list_name) do?
- Return the min as long as the list is well defined
What does max(list_name) do?
- Return the max as long as the list is well defined
What does sum(list_name) do?
- Returns the sum of elements as long as they’re numbers
What does remove(20) do?
- Remove element 20 from the list