In [ ]:
# list
my_list = [1, 4, 5, 9]
print(my_list)
In [ ]:
type(my_list)
In [ ]:
# accessing each element by index
print(my_list[2])
In [ ]:
len(my_list)
In [ ]:
# assigning new value
my_list[1] = 12
print(my_list)
In [ ]:
# append an element at the end
my_list.append(7)
print(my_list)
In [ ]:
help(list)
In [ ]:
# String
my_name = 'Anne' # it is also a tuple of characters
my_name[2]
In [ ]:
len(my_name)
In [ ]:
# sequence string separated by space
seq = 'AAA TTT CCC GGG'
print(seq.split())
In [ ]:
?str.split
In [ ]:
?str.join
In [ ]:
','.join(my_name)
In [ ]:
# Sets
my_set = set([1, 2, 3, 3, 3, 4])
print(my_set)
In [ ]:
len(my_set)
In [ ]:
my_set.add(3) # sets are unordered
print(my_set)
In [ ]:
my_set.remove(3)
print(my_set)
In [ ]:
# set operation using union | or intersection &
my_first_set = set([1, 2, 4, 6, 8])
my_second_set = set([8, 9, 10])
my_first_set | my_second_set
In [ ]:
my_first_set & my_second_set
In [ ]:
# Dictionnaries are collections of key/value pairs
my_dict = {'A': 'Adenine', 'C': 'Cytosine', 'T': 'Thymine', 'G': 'Guanine'}
print(my_dict)
In [ ]:
my_dict['C']
In [ ]:
my_dict['N']
In [ ]:
?my_dict.get
In [ ]:
my_dict.get('N', 'unknown')
In [ ]:
print(my_dict)
len(my_dict)
In [ ]:
type(my_dict)
In [ ]:
'T' in my_dict
In [ ]:
# Assign new key/value pair
my_dict['Y'] = 'Pyrimidine'
print(my_dict)
In [ ]:
my_dict['Y'] = 'Cytosine or Thymine'
print(my_dict)
In [ ]:
del my_dict['Y']
print(my_dict)
In [ ]:
help(dict)
In [ ]:
my_dict.keys()
In [ ]:
list(my_dict.keys())
In [ ]:
my_dict.values()
In [ ]:
my_dict.items()