# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # List and its default Functions

a = ["asish","rishabh","ankur"]
print(len(a))

#define a list
my_list = [4,7,0,3]

#get an iterator using iter()
my_iter = iter(my_list)

# +
#iterate through it using next()

#output:4
print(next(my_iter))
# -

#output:7
print(next(my_iter))

# +
#next(obj) is same as obj.__next__()

#output:0
print(my_iter.__next__())
# -

#output:3
print(my_iter.__next__())

#This will raise error,no items left
next(my_iter)

>>> for element in my_list:
    print (element)

# +
number = [1,2,3,4,5,6,7,8,9]
largest_number = max(number);

print("The largest number is:", largest_number)

# +
languages = ["Python", "C Programming", "Java"]
largest_string = max(languages);

print("The largest string is:", largest_string)

# +
number = [1,2,3,4,5,6,7,8,9]
smallest_number = min(number);

print("The smallest number is:", smallest_number)

# +
languages = ["Python", "C Programming", "Java"]
smallest_string = min(languages);

print("The smallest string is:", smallest_string)

# +
#How range works in python

#empty range
print(list(range(0)))

#using range(stop)
print(list(range(10)))

#using range(start, stop)
print(list(range(1, 10)))

# +
start=2
stop=14
step=2

print(list(range(start, stop, step)))
# -

# # Dictionary and its default Functions

# +
d= {1: "one", 2: "two"}

d.clear()
print('d =', d)

# +
original = {1: "one", 2: "two"}
new = original.copy()

print('original:', original)
print('new:', new)

# +
person = {'name': 'Asish', 'age':22}

print('Name: ',person.get('name'))
print('Age: ',person.get('age'))

#value is not provided
print('Salary: ',person.get('salary'))

#value is provided
print('Salary: ',person.get('salary',0.0))

# +
#random sales dictionary
sales = { 'apple': 2, 'orange': 3, 'grapes' : 4}

items = sales.items()
print('original items:', items)

#delete an item from dictionary
del[sales['apple']]
print('updated items:',items)

# +
person = {'name': 'Asish', 'age': 22, 'salary':3500.0}
print(person.keys())

empty_dict = {}
print(empty_dict.keys())

# +
#random sales dictionary
sales = { 'apple': 2, 'orange': 3, 'grapes' : 4}

element = sales.pop('apple')
print('The popped element is:',element)
print('The dictionary is:',sales)

# +
person = {'name': 'Asish', 'age': 22, 'salary':3500.0}

#('salary',3500.0)is inserted at the last,so it is removed.
result=person.popitem()

print('Return value =', result)
print('Person =', person)

#inserting a new element pair
person['profession'] = 'Plumber'

#now ('profession', 'plumber')is the lastest element
result=person.popitem()

print('Return value =', result)
print('Person =', person)

# +
person = {'name': 'Asish', 'age':22}

age=person.setdefault('age')
print('Person =', person)
print('Age =', age)

# +
d= {1: "one", 2: "three"}
d1= {2: "two"}

#update the value of key 2
d.update(d1)
print(d)

d1= {3: "three"}

#adds element with key 3
d.update(d1)
print(d)

# +
#random sales dictionary
sales = { 'apple': 2, 'orange': 3, 'grapes' : 4}

print(sales.values())
# -

# # Sets and its default Functions

# +
#set of vowels
vowels = {'a','e', 'i', 'u'}

#adding 'o'
vowels.add('o')
print('vowels are:',vowels)

#adding 'a' again
vowels.add('a')
print('vowels are:',vowels)

# +
#set of vowels
vowels = {'a', 'e', 'i', 'o', 'u'}
print('vowels(before clear):', vowels)

#clearing vowels
vowels.clear()
print('vowels(after clear):', vowels)

# +
numbers = {1,2,3,4}
new_numbers = numbers

new_numbers.add(5)

print('numbers:', numbers)
print('new_numbers:', new_numbers)

# +
A = {'a', 'b', 'c','d'}
B = {'c', 'f', 'g'}

#Equivalent to A-B
print(A.difference(B))

#Equivalent to B-A
print(B.difference(A))

# +
A = {'a', 'b', 'c','d'}
B = {'c', 'f', 'g'}

result = A.difference_update(B)

print('A = ', A)
print('B = ', B)
print('result = ', result)

# +
A = {'a', 'b', 'c','d'}

print('Return value is', A.pop())
print('A = ', A)

# +
#language set
language = {'English', 'French', 'German'}

#removing 'German' from language
language.remove('German')

#updated language set
print('updated language set:', language)

# +
A = {'a', 'c', 'd'}
B = {'c', 'd', 2}
C = {1,2,3}

print('A U B =', A.union(B))
print('B U C =', B.union(C))
print('A U B U C =', A.union(B, C))
print('A.union()=', A.union())

# +
A = {'a', 'b'}
B = {1,2,3}

result = A.update(B)
print('A = ', A)
print('result = ', result)
# -

# # Tuple and explore default methods

# +
#Use of Tuple count()

#Vowels tuple
vowels = ('a', 'e', 'i', 'o', 'i', 'u')

#count element 'i'
count = vowels.count('i')

#print count
print('The count of i is:', count)

#count element 'p'
count = vowels.count('p')

#print count
print('The count of p is:', count)

# +
#Vowels tuple
vowels = ('a', 'e', 'i', 'o', 'i', 'u')

#index of 'e' in vowels
index=vowels.index('e')
print('The index of e:', index)

#element of i is searched
#index of the first 'i' is returned
index = vowels.index('i')

print('The index of i:', index)
# -

# # String and explore default methods

# +
#define string
string = "Python is awesome,isn't it?"
substring = "is"

count = string.count(substring)

#print count
print("The count is:", count)

# +
string = "python is AWesome."

capitalized_string = string.capitalize()

print('Old String: ', string)
print('Capitalized String:', capitalized_string)

# +
# unicode string
string = 'pythön!'

# print string
print('The string is:', string)

# default encoding to utf-8
string_utf = string.encode()

# print result
print('The encoded version is:', string_utf)

# +
string = "Python is awesome"

new_string = string.center(24)

print("Centered String: ", new_string)

# +
s = 'this is good'
print(s.islower())

s = 'th!s is a1so g00d'
print(s.islower())

s = 'this is Not good'
print(s.islower())
# -



StarcoderdataJupyterScriptsDedupFiltered