List, Dictionary and Tuple
◤
List
List_a = [123, 456, 789, 10, 0, 454]
List name
elements
Values | 123 | 456 | 789 | 10 | 0 | 454 |
Index | 0 | 1 | 2 | 3 | 4 | 5 |
◤
Basic calling of a list
Values | Lakers | Bulls | Warriors | Nets | Spurs |
Forward index | 0 | 1 | 2 | 3 | 4 |
Reverse index | -5 | -4 | -3 | -2 | -1 |
◤
Basic operations of a list
Genes[1:5:2]
Start index
length
interval
genes | dnaA | NfkB | HER2 | ENG | p53 |
[2:5]
[1:-1]
[0:4]
[:4]
[1:5:2]
◤
Basic operations of a list
◤
Insert elements into a list
| insertion |
append | Add element to the end of list. |
extend | Add a list to end of another one |
insert | Insert a element to a specific index |
index
◤
Remove the elements from a list
◤
Useful functions for a list
◤
Useful functions for a list
◤
Useful functions for a list
◤
Exercise
| mutation |
Gene1 | No |
Gene2 | No |
Gene3 | Yes |
Gene4 | No |
Gene5 | Yes |
Gene6 | No |
Gene7 | No |
Gene8 | No |
We can do it better with if…else statement and loop
◤
Manage a string
◤
Manage a string
◤
Manage a string
This function is extremely useful to deal with fasta sequence
◤
Exercise
◤
Tuple
◤
Convert between list and tuple
◤
Dictionary (dict)
◤
Manage a dictionary
◤
Manage a dictionary
◤
Exercise
Name | Age | Gender | Duration | Syndromes |
John | 33 | Male | 7 | cough, fever, red skin |
Lucas | 23 | Male | 2 | cough, fever, vomit |
Amy | 60 | Female | 12 | cough, fever, vomit, headache |
Bill | 42 | Male | 13 | cough, fever, headache |
◤
◤