name = []
price = []
pages = []
n =["A","C","F"]
p=[100.00,256.50,233.70]
pg=[354,682,512]
print "Enter names, prices and no. of pages of 3 books "
for i in range(0,3):
#n,p,pg = raw_input("").split()
print n[i],p[i],pg[i]
name.append(n[i])
price.append(p[i])
pages.append(pg[i])
print "And this is what you entered"
for i in range(0,3):
print name[i], price[i], pages[i]
from collections import namedtuple
#Structure defintion
struct_book = namedtuple("struct_book", "name price pages")
#Input from user
print "Enter names, prices & no. of pages of 3 books"
#b1n,b1p,b1pg = raw_input("").split()
#b2n,b2p,b2pg = raw_input("").split()
#b3n,b3p,b3pg = raw_input("").split()
n =["A","C","F"]
p=[100.00,256.50,233.70]
pg=[354,682,512]
print n[0],p[0],pg[0]
print n[1],p[1],pg[1]
print n[2],p[2],pg[2]
#Structures for 3 books
b1 = struct_book(n[0], p[0], pg[0])
b2 = struct_book(n[1], p[1], pg[1])
b3 = struct_book(n[2], p[2], pg[2])
#Result
print "And this is what you entered"
print b1.name, b1.price, b1.pages
print b2.name, b2.price, b2.pages
print b3.name, b3.price, b3.pages
from collections import namedtuple
#Structure defintion
struct_book = namedtuple("struct_book", "name price pages")
#Structures for a book
b1 = struct_book('B', 130.00, 550)
#Result
print "Address of name = ", id(b1.name )
print "Address of price = ", id(b1.price )
print "Address of pages = ", id(b1.pages )
from collections import namedtuple
#Structure defintion
struct_book = namedtuple("struct_book", "name price pages")
#Array of structures
b =[]
n =["A","C","F"]
p=[100.00,256.50,233.70]
pg=[354,682,512]
#Storing data in the array
for i in range(0,3):
#bn, bp, bpg =raw_input( "Enter name, price and pages: " ).split()
print "Enter name, price and pages: "
print n[i],p[i],pg[i]
b.append(struct_book(n[i], p[i], pg[i]))
#Result
for i in range(0,3):
print b[i].name, b[i].price, b[i].pages
from collections import namedtuple
#Structure defintion
struct_employee = namedtuple("struct_employee", "name age salary")
#Structures for 3 employees
e1 = struct_employee("Sanjay", 30, 5500.50)
e2 = struct_employee(" ",0,0)
e3 = struct_employee(" ",0,0)
#piece-meal copying
import copy
e2 = e2._replace(name = e1.name)
e2 = e2._replace(age = e1.age)
e2 = e2._replace(salary = e1.salary)
#copying all elements at one go
e3 = e2
#Result
print e1.name, e1.age, e1.salary
print e2.name, e2.age, e2.salary
print e3.name, e3.age, e3.salary
from collections import namedtuple
#Structure defintions
struct_address = namedtuple("struct_address", "phone city pin")
struct_emp = namedtuple("struct_emp", "name struct_address") #nested structures
#Structures for employee
a = struct_address("531046", "nagpur", 10)
e = struct_emp("jeru",a) #nested structure
#Result
print "name = %s phone = %s" %( e.name, e.struct_address.phone )
print "city = %s pin = %d" %( e.struct_address.city, e.struct_address.pin )
from collections import namedtuple
#Structure defintions
struct_book = namedtuple("struct_book", "name author callno")
#Function definition
def display (s,t,n):
print s, t, n
#Structures for book
b1 = struct_book("Let us C", "YPK", 101)
display ( b1.name, b1.author, b1.callno ) #function call
from collections import namedtuple
#Structure defintions
struct_book = namedtuple("struct_book", "name author callno")
#Function definition
def display (b):
print b.name, b.author, b.callno
#Structures for book
b1 = struct_book("Let us C", "YPK", 101)
display ( b1) #function call
from collections import namedtuple
#Structure defintions
struct_book = namedtuple("struct_book", "name author callno")
#Structure for book
b1 = struct_book("Let us C", "YPK", 101)
ptr = id(b1) #structure pointer
#Result
print b1.name, b1.author, b1.callno
print b1.name, b1.author, b1.callno
#function definition
def display (b):
print b.name, b.author, b.callno
from collections import namedtuple
#Structure defintions
struct_book = namedtuple("struct_book", "name author callno")
#Structure for book
b1 = struct_book("Let us C", "YPK", 101)
#function call
display ( b1 )