Python Programing Lab (R16) EXERCISE - 5(b)

Python Programing Lab (R16) EXERCISE - 5(b)


Aim:

Write a program to use split and join methods in the string and trace a birthday with a dictionary data structure.

Description:

Compare the entered birthdate with each and every person‟s date of birth in the dictionary and check whether the entered birthdate is present in the dictionary or not. Here, We are using two built-in methods of the string: split() and join().

split():
This method breaks up a string using the specified separator and returns a list of strings. The general form of split() is as follows:

str.split(separator)

join():
This method provides a flexible way to concatenate a string. This method returns a string inwhich the string elements of a sequence have been joined by „sep‟ separator. The general form of join() is as follows:
sep.join(sequence)

Here, sequence is the sequence of elements to be joined.

Program:

pen='+'
pin=['H','E','L','L','O']
print("Joining")
print(pen.join(pin))
c=pen.join(pin)
print("Splitting")
print(c.split('+'))
people={
   'Netaji':{
       'birthday':'Aug 15'
    },
   'Manaswi':{
       'birthday':'Mar 21'
    },
   'Chandrika':{
       'birthday':'July 7'
    }
}
labels={
    'birthday':'birth date'
}
name=input("Name:")
request=input('birthday(b)?')
if request=='b':
   key='birthday'
if name in people:
   print("%s's %s is %s." % (name, labels[key], people[name][key]))

Output:


1 comment

JavaFX Scene Builder

  This is an article about the JavaFX Scene Builder. You will get a short introduction about the installation and usage of the software. The...