1
00:00:00,000 --> 00:00:03,600
A list preserves an ordered sequence that
you can change.

2
00:00:03,680 --> 00:00:06,880
A tuple holds a fixed sequence of
references.

3
00:00:06,960 --> 00:00:11,520
A dictionary maps unique keys to values
and preserves insertion order.

4
00:00:11,600 --> 00:00:15,440
A set represents distinct members without
a defined order.

5
00:00:15,600 --> 00:00:18,720
These four built in types solve different
problems.

6
00:00:18,760 --> 00:00:23,520
We will use invented gene names,
expression values, and sample metadata to

7
00:00:23,680 --> 00:00:27,920
trace their operations, then connect the
choices to interview questions.

8
00:00:28,233 --> 00:00:31,593
Start with the relationship your data must
represent.

9
00:00:31,673 --> 00:00:35,220
Gene names in a chosen order form a
sequence.

10
00:00:35,406 --> 00:00:39,073
Expression values addressed by gene symbol
form a mapping.

11
00:00:39,113 --> 00:00:43,353
Choose how you will retrieve a value: by
position, by key, or by

12
00:00:43,913 --> 00:00:44,513
membership.

13
00:00:44,553 --> 00:00:49,406
Check whether order, repeated values, and
later changes belong in the problem.

14
00:00:49,460 --> 00:00:53,166
This decision comes before choosing
brackets or braces.

15
00:00:53,220 --> 00:00:57,993
Curly braces alone create an empty
dictionary; use set with parentheses for

16
00:00:58,073 --> 00:00:59,353
an empty set.

17
00:00:59,600 --> 00:01:03,520
Index zero retrieves T P fifty three from
the five gene

18
00:01:03,600 --> 00:01:04,613
list.

19
00:01:04,747 --> 00:01:08,440
Index minus one retrieves M Y C from the
end.

20
00:01:08,480 --> 00:01:13,360
The slice from one to three includes
positions one and two, giving B R C

21
00:01:13,440 --> 00:01:15,880
A one and E G F R.

22
00:01:15,920 --> 00:01:18,213
The stop position is excluded.

23
00:01:18,267 --> 00:01:22,800
A slice creates a new outer list
containing the selected references; it

24
00:01:22,920 --> 00:01:25,813
does not recursively copy nested objects.

25
00:01:25,867 --> 00:01:30,480
An indexed access outside the list raises
IndexError, while ordinary slice

26
00:01:30,560 --> 00:01:33,440
boundaries are clipped to the available
sequence.

27
00:01:33,700 --> 00:01:36,420
Begin with the original five gene names.

28
00:01:36,700 --> 00:01:40,180
Append adds P T E N at the end of the
list.

29
00:01:40,460 --> 00:01:45,260
Remove searches for the first matching K R
A S value and deletes it.

30
00:01:45,300 --> 00:01:50,100
It takes a value rather than a position;
pop uses a position and returns the

31
00:01:50,180 --> 00:01:51,407
removed item.

32
00:01:51,433 --> 00:01:54,820
The remaining list preserves the order of
the other genes.

33
00:01:54,900 --> 00:01:59,300
These methods change the existing list, so
another name for that same list sees the

34
00:01:59,380 --> 00:02:00,140
change.

35
00:02:00,180 --> 00:02:02,633
Append and remove return None.

36
00:02:02,687 --> 00:02:06,020
Do not assign their return values back to
your list variable.

37
00:02:06,300 --> 00:02:10,060
A transformation applies an expression to
every item.

38
00:02:10,100 --> 00:02:15,020
The lesson computes log base two of each
count plus one and stores the results

39
00:02:15,100 --> 00:02:16,380
in a new list.

40
00:02:16,460 --> 00:02:20,020
A filter keeps only values that satisfy a
condition.

41
00:02:20,060 --> 00:02:24,580
Here the comparison retains p values below
zero point zero five,

42
00:02:24,620 --> 00:02:29,420
producing zero point zero zero one, zero
point zero four, and zero point

43
00:02:29,500 --> 00:02:31,047
zero zero five.

44
00:02:31,073 --> 00:02:33,313
The result follows the input order.

45
00:02:33,367 --> 00:02:37,927
This is a Python filter demonstration, not
a multiple testing decision rule.

46
00:02:37,953 --> 00:02:42,860
For a family of gene tests, use adjusted p
values and the statistical rule explained

47
00:02:42,900 --> 00:02:44,220
on the linked page.

48
00:02:44,467 --> 00:02:48,627
The gene record contains B R C A one,
chromosome

49
00:02:48,707 --> 00:02:51,427
seventeen, and an illustrative position.

50
00:02:51,467 --> 00:02:56,387
The coordinate is only a Python record
here; a real genomic location also needs

51
00:02:56,467 --> 00:02:58,987
an assembly and coordinate convention.

52
00:02:59,027 --> 00:03:03,347
Unpacking assigns the three elements to
gene, chromosome, and position

53
00:03:03,427 --> 00:03:04,907
variables in order.

54
00:03:04,947 --> 00:03:09,507
An immutable tuple prevents you from
replacing, adding, or removing its element

55
00:03:10,027 --> 00:03:10,587
references.

56
00:03:10,627 --> 00:03:13,934
A list stored inside a tuple can still
change.

57
00:03:13,960 --> 00:03:18,147
A tuple is hashable only when all its
elements are hashable, so a tuple

58
00:03:18,267 --> 00:03:21,107
containing a list cannot be a dictionary
key.

59
00:03:21,333 --> 00:03:26,173
The gene symbol is the dictionary key and
the expression measurement is its value.

60
00:03:26,213 --> 00:03:30,826
Looking up B R C A one returns forty five
point two.

61
00:03:30,960 --> 00:03:35,573
Assigning a new key adds a measurement;
assigning an existing key replaces its

62
00:03:35,653 --> 00:03:38,426
value rather than adding a duplicate key.

63
00:03:38,480 --> 00:03:42,240
The items method yields key and value
pairs for a loop.

64
00:03:42,266 --> 00:03:46,853
Dictionaries preserve insertion order in
Python three point seven and later, but

65
00:03:46,933 --> 00:03:49,373
the keys are not automatically sorted.

66
00:03:49,413 --> 00:03:51,066
Keys must be hashable.

67
00:03:51,120 --> 00:03:54,373
Their values can be lists or other mutable
objects.

68
00:03:54,600 --> 00:03:58,600
Square bracket access raises KeyError when
the requested key is

69
00:03:58,680 --> 00:03:59,640
absent.

70
00:03:59,720 --> 00:04:02,760
The get method can return a default
instead.

71
00:04:02,840 --> 00:04:07,760
Our dictionary has no P T E N measurement,
so get returns None.

72
00:04:07,800 --> 00:04:11,600
A measured zero would be a different value
with a different meaning.

73
00:04:11,640 --> 00:04:15,960
Use key membership when you must
distinguish an absent key from a key whose

74
00:04:16,040 --> 00:04:17,800
stored value is None.

75
00:04:17,960 --> 00:04:21,280
Dictionary membership tests keys, not
values.

76
00:04:21,320 --> 00:04:25,160
Choosing the right missing value behavior
prevents an absent measurement from

77
00:04:25,240 --> 00:04:27,800
becoming an invented biological zero.

78
00:04:28,033 --> 00:04:32,593
The intersection contains genes present in
both the upregulated set and the

79
00:04:32,673 --> 00:04:36,753
pathway set: E G F R and T P fifty three.

80
00:04:36,793 --> 00:04:40,593
The difference keeps genes in the
upregulated set that are absent from the

81
00:04:40,673 --> 00:04:43,833
pathway: M Y C and P T E N.

82
00:04:43,873 --> 00:04:47,206
Reversing the operands would answer a
different question.

83
00:04:47,260 --> 00:04:51,273
The union contains all six distinct genes
from either set.

84
00:04:51,313 --> 00:04:54,233
We sort each result for a stable display.

85
00:04:54,273 --> 00:04:58,993
Sorted returns a list; it does not give
the stored set an element order.

86
00:04:59,233 --> 00:05:04,193
Converting to a set removes duplicate gene
names and loses their original sequence

87
00:05:04,273 --> 00:05:05,073
order.

88
00:05:05,273 --> 00:05:08,153
Sorting the result produces alphabetical
order.

89
00:05:08,193 --> 00:05:12,913
In this example that gives B R C A one, E
G F R, and T P

90
00:05:12,993 --> 00:05:14,193
fifty three.

91
00:05:14,273 --> 00:05:17,500
Preserving first occurrence requires a
different choice.

92
00:05:17,526 --> 00:05:21,873
A dictionary built with from keys retains
the first insertion order of these

93
00:05:21,993 --> 00:05:26,273
hashable strings; converting its keys to a
list gives T P fifty

94
00:05:26,433 --> 00:05:29,913
three, B R C A one, and E G F R.

95
00:05:29,953 --> 00:05:34,113
Decide which order the caller expects
before selecting a deduplication

96
00:05:34,193 --> 00:05:35,233
expression.

97
00:05:35,467 --> 00:05:39,387
The outer dictionary maps each sample
identifier to a metadata

98
00:05:39,467 --> 00:05:40,507
dictionary.

99
00:05:40,587 --> 00:05:43,907
The inner dictionary maps a field name to
its value.

100
00:05:43,947 --> 00:05:48,134
Selecting S one and then condition returns
control.

101
00:05:48,240 --> 00:05:52,507
Selecting S two and then read count
returns thirty one million.

102
00:05:52,587 --> 00:05:56,347
A shallow copy of the outer dictionary
still refers to the same inner

103
00:05:56,427 --> 00:05:57,654
dictionaries.

104
00:05:57,760 --> 00:06:02,000
Changing an inner field through that copy
changes what the original sees.

105
00:06:02,054 --> 00:06:06,427
A separate nested copy is needed when the
caller expects those inner records to

106
00:06:06,507 --> 00:06:08,027
change independently.

107
00:06:08,267 --> 00:06:13,067
A Python list supports constant time
indexed access and amortized constant

108
00:06:13,187 --> 00:06:14,427
time append.

109
00:06:14,507 --> 00:06:17,827
Front insertion and value search take
linear time.

110
00:06:17,867 --> 00:06:22,827
A dictionary or set normally supports
constant average time key or membership

111
00:06:23,187 --> 00:06:27,587
lookup, assuming well behaved hashes and
bounded key comparison costs.

112
00:06:27,627 --> 00:06:29,654
Worst cases can be linear.

113
00:06:29,680 --> 00:06:33,787
The interview explanation should name the
required operation, whether the code

114
00:06:33,867 --> 00:06:37,840
changes the input, and how much additional
memory it allocates.

115
00:06:37,894 --> 00:06:42,187
The full lesson contains executable
examples; the interview course develops

116
00:06:42,267 --> 00:06:46,987
stacks, queues, linked lists, trees,
heaps, and graphs from these

117
00:06:47,147 --> 00:06:48,107
foundations.
