In [1]:
days = ['yesterday','today','tomorrow','dayafter']

In [2]:
# task1
for value in days:
    print value,len(value)


yesterday 9
today 5
tomorrow 8
dayafter 8

In [4]:
# task2
for value in days:
    print value,days.index(value)


yesterday 0
today 1
tomorrow 2
dayafter 3

In [5]:
for value in days:
    print value,days.index(value),value[days.index(value)]


yesterday 0 y
today 1 o
tomorrow 2 m
dayafter 3 a

In [7]:
for value in days:
    print value,days.index(value),value[0:days.index(value) + 1]


yesterday 0 y
today 1 to
tomorrow 2 tom
dayafter 3 daya

In [8]:
# my_string
my_string="python"
print my_string[0:3] # pyt
print my_string[:3] # pyt
print my_string[3:] # hon
print my_string[:3] + my_string[3:]


pyt
pyt
hon
python

In [10]:
for value in days:
    print value[:days.index(value) + 1].upper() + value[days.index(value) + 1:]


Yesterday
TOday
TOMorrow
DAYAfter

In [4]:
# task2
my_fruits = ['apple','apple','banana','banana','banana','cherry','apple']
# my_fruits = ['apple','banana','cherry']
# my_dupli = ['apple','banana']

my_dupli=[]
for value in my_fruits:
    print "looking into value - {}".format(value)
    if my_fruits.count(value) > 1:
        if not value in my_dupli:
            my_dupli.append(value)
        my_fruits.remove(value)
        
print my_fruits
print my_dupli


looking into value - apple
looking into value - banana
looking into value - banana
looking into value - apple
['banana', 'cherry', 'apple']
['apple', 'banana']

In [5]:
# deep copy
my_fruits =['apple','banana','cherry']
my_new = my_fruits[:]
print my_fruits,my_new
print my_fruits is my_new


['apple', 'banana', 'cherry'] ['apple', 'banana', 'cherry']
False

In [6]:
import copy
my_fruits =['apple','banana','cherry']
my_new = copy.deepcopy(my_fruits)
print my_fruits,my_new
print my_fruits is my_new


['apple', 'banana', 'cherry'] ['apple', 'banana', 'cherry']
False

In [7]:
# soft copy
my_fruits =['apple','banana','cherry']
my_new = my_fruits
print my_fruits,my_new
print my_fruits is my_new


['apple', 'banana', 'cherry'] ['apple', 'banana', 'cherry']
True

In [ ]: