list = []
list2 = [1, 'hello world', True, list]
list2
list3 = [1,2,3]
list3 + list2
len(list3)
list3 * 2
list3[0]
list3[-1]
list3
list3[0] = 10
list3
a = list3
a
b = a
b
a[1] = 20
a
b
c = a.copy()
dir(a)
c = a[:]
a
c
a[-1] = 30
a
c
[1,2,3] == [1,3,2]
list4 = [0,1,2,3,4,5]
list4[0:2]
1 in list4
10 in list4
list4
list4.append(6)
list4
list4.pop()
list4
list4.pop(0)
list4
x = list4.append(6)
x
list4
y = list4.pop()
y
y
del y
y
list4
del list4[-1]
list4
dir(list4)
sorted(list4)
list4
list5 = [1,3,2,5,4]
sorted(list5)
list5
list5.sort()
list5
list5 = [1,3,2,5,4]
sorted(list5, reverse=True)
list6 = ['a', 'aaa', 'aa']
sorted(list6, key=len)
sorted(list6, key=len, reverse=True)
list6
list7 = ['aa', 'b', 'ccc']
';'.join(list7)
x = ';'.join(list7)
x
x.split(';')
# tuple
tuple1 = ()
tuple2 = (1, 3, 5)
tuple2[0] = 10
(x, y) = (1, 3)
x
y
list1 = (1, 2, 'hello', tuple2)
list1
list1[-1][0] = 10
list(tuple2)
tuple2
list
del list
list(tuple2)
!pwd
! echo "Line1: Hello World" > data1.txt
! echo "Line2: Hello people" >> data1.txt
! echo "Line2: Hello you" >> data1.txt
!cat data1.txt
fp = open('data1.txt')
for line in fp:
print line
fp = open('data1.txt')
for line in fp:
print line,
fp = open('data1.txt')
line_list = fp.readlines()
line_list
fp = open('data1.txt')
string1 = fp.read()
string1
string1.count('Hello')
fw = open('data2.txt', 'w')
!cat data1.txt
! echo "Line1: Hello World" > data1.txt
! echo "Line1: Hello People" >> data1.txt
! echo "Line1: Hello You" >> data1.txt
cat data1.txt
string1 = open('data1.txt').read()
fw
fw.write(string1)
fw.close()
!cat data2.txt
string1
fw = open('data2.txt', 'w')
string2 = 'This is a string'
fw.write(string2)
fw.close()
!cat data2.txt
l = ['', 'xyzzz', 'aabddda', 'xyx', 'bbbb']
for i in l:
if len(i) > 2 and i[0] == i[-1]:
print i
# 2) remove the duplicates in the following list
l = [1,2,2,3,3,5,4,1,1,1]
new_list = []
for i in l:
if not i in new_list:
# add it
new_list.append(i)
print new_list
!curl http://lyorn.idyll.org/~gjr/public2/swc/1k.taxonomy -O
# collect unique
unique_list = []
# collect all
all_list = []
for line in open('1k.taxonomy'):
# +++add your code+++
name, taxon = line.rstrip().split('\t')
domain = taxon.split(';')[0]
all_list.append(domain)
if not domain in unique_list:
unique_list.append(domain)
# count unique, hint: list.count
# +++add your code+++
for i in unique_list:
count = all_list.count(i)
print i, count
pwd