diff --git a/en-US/datastructure.xml b/en-US/datastructure.xml
index 5239f98..993138c 100644
--- a/en-US/datastructure.xml
+++ b/en-US/datastructure.xml
@@ -10,50 +10,50 @@
Lists
->> a = [23, 45, 1, -3434, 43624356, 234]
+>> a = [23, 45, 1, -3434, 43624356, 234]
>>> a.append(45)
>>> a
[23, 45, 1, -3434, 43624356, 234, 45]
]]>
-
+
At first we created a list a. Then to add 45 at the end of the list we call a.append(45) method. You can see that 45 added at the end of the list. Sometimes it may require to insert data at any place within the list, for that we have insert() method.
->> a.insert(0, 1) # 1 added at the 0th position of the list
+>> a.insert(0, 1) # 1 added at the 0th position of the list
>>> a
[1, 23, 45, 1, -3434, 43624356, 234, 45]
>>> a.insert(0, 111)
>>> a
[111, 1, 23, 45, 1, -3434, 43624356, 234, 45]
]]>
-
+
count(s) will return you number of times s is in the list. Here we are going to check how many times 45 is there in the list.
->> a.count(45)
+>> a.count(45)
2
]]>
-
+
If you want to any particular value from the list you have to use remove() method.
->> a.remove(234)
+>> a.remove(234)
>>> a
[111, 1, 23, 45, 1, -3434, 43624356, 45]
]]>
-
+
Now to reverse the whole list
->> a.reverse()
+>> a.reverse()
>>> a
[45, 43624356, -3434, 1, 45, 23, 1, 111]
]]>
-
+
We can store anything in the list, so first we are going to add another list b in a , then we will learn how to add the values of b into a .
->> b = [45, 56, 90]
+>> b = [45, 56, 90]
>>> a.append(b)
>>> a
[45, 43624356, -3434, 1, 45, 23, 1, 111, [45, 56, 90]]
@@ -65,23 +65,23 @@
>>> a[-1]
90
]]>
-
+
Above you can see how we used a.extend() method to extend the list. To sort any list we have sort() method.
->> a.sort()
+>> a.sort()
>>> a
[-3434, 1, 1, 23, 45, 45, 45, 56, 90, 111, 43624356, [45, 56, 90]]
]]>
-
+
You can also delete element at any particular position of the list using the del keyword.
->> del a[-1]
+>> del a[-1]
>>> a
[-3434, 1, 1, 23, 45, 45, 45, 56, 90, 111, 43624356]
]]>
-
+
@@ -90,7 +90,7 @@
Stacks are often known as LIFO (Last In First Out) structure. It means the data will enter into it at the end , and the last data will come out first. The easiest example can be of couple of marbles in an one side closed pipe. So if you want to take the marbles out of it you have to do that from the end where you entered the last marble. To achieve the same in code
->> a
+>> a
[1, 2, 3, 4, 5, 6]
>>> a.pop()
6
@@ -106,14 +106,14 @@
>>> a
[1, 2, 34)
]]>
-
+
We learned a new method above pop(). pop(i) will take out the ith data from the list.
In our daily life we have to encounter queues many times, like in ticket counters or in library or in the billing section of any supermarket. Queue is the data structure where you can append more data at the end and take out data from the beginning. That is why it is known as FIFO (First In First Out).
->> a = [1, 2, 3, 4, 5]
+>> a = [1, 2, 3, 4, 5]
>>> a.append(1)
>>> a
[1, 2, 3, 4, 5, 1]
@@ -124,7 +124,7 @@
>>> a
[3, 4, 5, 1]
]]>
-
+
To take out the first element of the list we are using a.pop(0).
@@ -138,7 +138,7 @@
For example if we want to make a list out of the square values of another list, then
->> a = [1, 2, 3]
+>> a = [1, 2, 3]
>>> [x ** 2 for x in a]
[1, 4, 9]
>>> z = [x + 1 for x in [x ** 2 for x in a]]
@@ -146,7 +146,7 @@
[2, 5, 10]
]]>
-
+
Above in the second case we used two list comprehensions in a same line.
@@ -157,7 +157,7 @@
Tuples are data separated by comma.
->> a = 'Fedora', 'Debian', 'Kubuntu', 'Pardus'
+>> a = 'Fedora', 'Debian', 'Kubuntu', 'Pardus'
>>> a
('Fedora', 'Debian', 'Kubuntu', 'Pardus')
>>> a[1]
@@ -167,11 +167,11 @@
...
Fedora Debian Kubuntu Pardus
]]>
-
+
You can also unpack values of any tuple in to variables, like
->> divmod(15,2)
+>> divmod(15,2)
(7, 1)
>>> x, y = divmod(15,2)
>>> x
@@ -179,24 +179,24 @@ Fedora Debian Kubuntu Pardus
>>> y
1
]]>
-
+
Tuples are immutable, that means you can not del/add/edit any value inside the tuple. Here is another example
->> a = (1, 2, 3, 4)
+>> a = (1, 2, 3, 4)
>>> del a[0]
Traceback (most recent call last):
File "", line 1, in
TypeError: 'tuple' object doesn't support item deletion
]]>
-
+
Above you can see python is giving error when we are trying to delete a value in the tuple.
To create a tuple which contains only one value you have to type a trailing comma.
->> a = (123)
+>> a = (123)
>>> a
123
>>> type(a)
@@ -207,14 +207,14 @@ TypeError: 'tuple' object doesn't support item deletion
>>> type(a)
]]>
-
+
Using the buitin function type() you can know the data type of any variable. Remember the len() function we used to find the length of any sequence ?
->> type(len)
+>> type(len)
]]>
-
+
@@ -222,15 +222,15 @@ TypeError: 'tuple' object doesn't support item deletion
Sets are another type of data structure with no duplicate items. We can also mathematical set operations on sets.
->> a = set('abcthabcjwethddda')
+>> a = set('abcthabcjwethddda')
>>> a
set(['a', 'c', 'b', 'e', 'd', 'h', 'j', 't', 'w'])
]]>
-
+
And some examples of the set operations
->> a = set('abracadabra')
+>> a = set('abracadabra')
>>> b = set('alacazam')
>>> a # unique letters in a
set(['a', 'r', 'b', 'c', 'd'])
@@ -243,17 +243,17 @@ set(['a', 'c'])
>>> a ^ b # letters in a or b but not both
set(['r', 'd', 'b', 'm', 'z', 'l'])
]]>
-
+
To add or pop values from a set
->> a
+>> a
set(['a', 'c', 'b', 'e', 'd', 'h', 'j', 'q', 't', 'w'])
>>> a.add('p')
>>> a
set(['a', 'c', 'b', 'e', 'd', 'h', 'j', 'q', 'p', 't', 'w'])
]]>
-
+
@@ -261,50 +261,50 @@ set(['a', 'c', 'b', 'e', 'd', 'h', 'j', 'q', 'p', 't', 'w'])
Dictionaries are unordered set of key: value pairs where keys are unique. We declare dictionaries using {} braces. We use dictionaries to store data for any particular key and then retrieve them.
->> data = {'kushal':'Fedora', 'kart_':'Debian', 'Jace':'Mac'}
+>> data = {'kushal':'Fedora', 'kart_':'Debian', 'Jace':'Mac'}
>>> data
{'kushal': 'Fedora', 'Jace': 'Mac', 'kart_': 'Debian'}
>>> data['kart_']
'Debian'
]]>
-
+
We can add more data to it by simply
->> data['parthan'] = 'Ubuntu'
+>> data['parthan'] = 'Ubuntu'
>>> data
{'kushal': 'Fedora', 'Jace': 'Mac', 'kart_': 'Debian', 'parthan': 'Ubuntu'}
]]>
-
+
To delete any particular key:value pair
->> del data['kushal']
+>> del data['kushal']
>>> data
{'Jace': 'Mac', 'kart_': 'Debian', 'parthan': 'Ubuntu'
]]>
-
+
To check if any key is there in the dictionary or not you can use in keyword.
->> 'Soumya' in data
+>> 'Soumya' in data
False
]]>
-
+
You must remember that no mutable object can be a key, that means you can not use a list as a key.
dict() can create dictionaries from tuples of key,value pair.
->> dict((('Indian','Delhi'),('Bangladesh','Dhaka')))
+>> dict((('Indian','Delhi'),('Bangladesh','Dhaka')))
{'Indian': 'Delhi', 'Bangladesh': 'Dhaka'}
]]>
-
+
If you want to loop through a dict use iteritems() method.
->> data
+>> data
{'Kushal': 'Fedora', 'Jace': 'Mac', 'kart_': 'Debian', 'parthan': 'Ubuntu'}
>>> for x, y in data.iteritems():
... print "%s uses %s" % (x, y)
@@ -314,22 +314,48 @@ Jace uses Mac
kart_ uses Debian
parthan uses Ubuntu
]]>
-
+
+
+ Many times it happens that we want to add more data to a value in a dictionary and if the key does not exists then we add some default value. You can do this efficiently using dict.setdefault(key, default).
+
+>>> data = {}
+>>> data.setdefault('names', []).append('Ruby')
+>>> data
+{'names': ['Ruby']}
+>>> data.setdefault('names', []).append('Python')
+>>> data
+{'names': ['Ruby', 'Python']}
+>>> data.setdefault('names', []).append('C')
+>>> data
+{'names': ['Ruby', 'Python', 'C']}
+
+
+
+ When we try to get value for a key which does not exists we get KeyError. We can use dict.get(key, default) to get a default value when they key does not exists before.
+
+
+>>> data['foo']
+Traceback (most recent call last):
+ File "", line 1, in
+KeyError: 'foo'
+>>> data.get('foo', 0)
+0
+
If you want to loop through a list (or any sequence) and get iteration number at the same time you have to use enumerate().
->> for i, j in enumerate(['a', 'b', 'c']):
+>> for i, j in enumerate(['a', 'b', 'c']):
... print i, j
...
0 a
1 b
2 c
]]>
-
+
You may also need to iterate through two sequences same time, for that use zip() function.
->> a = ['Pradeepto', 'Kushal']
+>> a = ['Pradeepto', 'Kushal']
>>> b = ['OpenSUSE', 'Fedora']
>>> for x, y in zip(a, b):
... print "%s uses %s" % (x, y)
@@ -337,7 +363,7 @@ parthan uses Ubuntu
Pradeepto uses OpenSUSE
Kushal uses Fedora
]]>
-
+
@@ -367,7 +393,7 @@ for x, y in data.iteritems():
The output
-
-
+
@@ -415,7 +441,7 @@ print "-" * 10 * n
The output
-
-
+
Here we have used list comprehensions couple of times. [int(x) for x in raw_input("").split(" ")] here first it takes the input as string by raw_input(), then split the result by " ", then for each value create one int. We are also using [a[i][j] * b[j][i] for j in range(0,n)] to get the resultant row in a single line.