row1 = [13,25,73]
row2 = [54,95,36]
row3 = [27,98,19]
matrix = [row1, row2, row3]
trmatrix = [[row[0] for row in matrix],[row[1] for row in matrix], [row[2] for row in matrix]]
print'Transpose of a matrix',trmatrix
source: http://stackoverflow.com
Solve Problems by Coding Solutions - A Complete solution for python programming
Manipulation the Dictionary
d={10: 'iprg' , 22: 'Nan', 33:'Kool',8: 'Jool','y': 89,'tt':'toy',7:90 }
for i in d:
print i,d[i] # printing all the values in Dictionary
print '\n'
print d[8] #printing values of the individual keys
print '\n'
print d['y'] #printing values of the individual keys
print '\n'
print d[7] #printing values of the individual keys
print '\n'
d[33]='hello world' #updating the key 33 with new value
d[22]='pythonforengineers' #updating the key 22 with new value
for i in d:
print i,d[i] # printing all the updated values in Dictionary
del d[10] # deleting key:value pair using key value -> 10
print'\n Dictionary after deleting a value:\n', d
d.clear() #clearing all values
print '\n Dictionary after clearing all values:', d
del d # Removing the Dictionary
try:
print d
except:
print 'Some error has occurred'
for i in d:
print i,d[i] # printing all the values in Dictionary
print '\n'
print d[8] #printing values of the individual keys
print '\n'
print d['y'] #printing values of the individual keys
print '\n'
print d[7] #printing values of the individual keys
print '\n'
d[33]='hello world' #updating the key 33 with new value
d[22]='pythonforengineers' #updating the key 22 with new value
for i in d:
print i,d[i] # printing all the updated values in Dictionary
del d[10] # deleting key:value pair using key value -> 10
print'\n Dictionary after deleting a value:\n', d
d.clear() #clearing all values
print '\n Dictionary after clearing all values:', d
del d # Removing the Dictionary
try:
print d
except:
print 'Some error has occurred'
Subscribe to:
Posts (Atom)