Unit 11 : Data Collection Flashcards

1
Q

What does rstrip() does?

A
  1. Remove the white space at right side
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does find() does?

A
  1. Find the string inside a file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What allows duplicate data, ordered and changeable?

A
  1. List

mylist = [1,2,3]

  • Arrary , the order [0]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What allows duplicate data, ordered and unchangeable?

A
  1. Tuple

mytuple = ( “Adam”,”bob”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What doesn’t allow duplicate data, unordered, unchangeable and unindexed?

A
  1. Set

myset = { “Dan” , “Chris”}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What doesn’t allow duplicate data, ordered and changeable?

A
  1. Dictionary

mydict = {
“name” : “Adam” ,
“password” : “123” ,
“role” : “chef”
}

print(mydict[“password”])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is list used for?

A
  1. Group similar items
  • Ordered, changeable and allow duplicate values
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is list defined by?

A
  1. Square brackets [ ]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How can we create list ? ( 4 )

A
  1. new_list = []
  2. new_list = [ 3, 4, 5, 6 ]
  3. new_list = list(range(10))
  4. new_list = list(range(2,7))
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How can we add element? ( 2 )

A
  1. new_list[3] = 145
  2. new_list.append(3)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Can list insert different types of data ? ( newlist = [ 1 , “Adam” ] )

A
  1. Yes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to add another list ? ( 2 )

A
  1. new_list[2] = new_list2
  2. newlist,append(new_list[2])
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to print out the list?

A
  1. print(new_list)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to print the exact list?

A
  1. print(new_list[2])
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to print the list range?

A
  1. print(new_list[0:3])
  • This will take the value in list between 0 , 1 , 2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to scan through the lists?

A

new_list = [ 3, 4, 5, 6 ]
for i in new_list:
print(i)

  • This can print the values inside the list without []
17
Q

How to search for an element?

A

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”)

18
Q

What does append do?

A
  1. Add an element at the end
19
Q

What does insert(0,200) do?

A
  1. Insert at position 0 the element 200
20
Q

What does len(list_name) do?

A
  1. Return the length
21
Q

What does min(list_name) do?

A
  1. Return the min as long as the list is well defined
22
Q

What does max(list_name) do?

A
  1. Return the max as long as the list is well defined
23
Q

What does sum(list_name) do?

A
  1. Returns the sum of elements as long as they’re numbers
24
Q

What does remove(20) do?

A
  1. Remove element 20 from the list
25
Q

What does pop(2) do?

A
  1. Removes element at index 2
26
Q

What values does dictionary wants?

A
  1. Collection of data
    • store values in key:value pairs key : value ( “name” : “Adam” )
27
Q

Can we store dictionary in what file?

A
  1. json file
28
Q

How can we read and write file?

A
  1. dump() - write
  2. load() - read
29
Q

Write a program to
1. Create a empty dictionary
2. Add item into dictionary
3. Accessing items inside dictionary

A

newstudent = {}

newstudent[“TP”] = “TP123456”
newstudent[“Name”] = “John”

print(newstudent.get(“Name”)

30
Q

What does clear() and copy() do in dictionary?

A
  1. clear() - Removes all elements from the dictionary
  2. copy() - Returns a copy of the dictionary
31
Q
A