In [ ]:
#Sorted List
original_list = [4,1,5,2,3]
# sorted_list = sorted(original_list)
original_list.sort()
ol = original_list
print(ol)
[1, 2, 3, 4, 5]
In [ ]:
hex = int("3ff", 16)
print(hex)
1023
In [ ]:
num = 6.023e23
sum = num * 16
print(type(sum))
<class 'float'>
List are mutable but Tuple and String are Immutable¶
In [ ]:
L = [1,2,3,4,5]
T = (1,2,3,4,5)
S = "Numbers"
L[1]=10
print(L)
[1, 10, 3, 4, 5]
String Delimiter¶
In [ ]:
print("""Welcome to the GPA calculator.
Please enter all your letter grades, one per line.
Enter a blank line to designate the end.""")
Welcome to the GPA calculator. Please enter all your letter grades, one per line. Enter a blank line to designate the end.
Unique Letters in my name¶
In [ ]:
my_name_letters = set("MD ABDULLAH AL MAMUN".replace(" ",""))
print(my_name_letters)
print(len(my_name_letters))
{'M', 'A', 'H', 'U', 'L', 'D', 'N', 'B'} 8
Dictionary¶
In [ ]:
mydict = dict([('ga','Irish'),('de','German')])
print(mydict)
{'ga': 'Irish', 'de': 'German'}
In [ ]:
type(mydict)
Out[ ]:
dict
In [ ]:
for e,f in mydict.items():
print(f"{e} : {f} n {len(e)} + {len(f)} = {len(e)+len(f)}")
ga : Irish 2 + 5 = 7 de : German 2 + 6 = 8
In [ ]:
new_dict = {'A':1,'B':2}
print(new_dict)
{'A': 1, 'B': 2}
In [ ]:
print(chr(65))
A
Character Game¶
In [ ]:
# Create a Dictionary with the alphabet number
alphabet = {}
for i in range(1,27):
alphabet[chr(i+64)]=i
In [ ]:
print(alphabet)
{'A': 1, 'B': 2, 'C': 3, 'D': 4, 'E': 5, 'F': 6, 'G': 7, 'H': 8, 'I': 9, 'J': 10, 'K': 11, 'L': 12, 'M': 13, 'N': 14, 'O': 15, 'P': 16, 'Q': 17, 'R': 18, 'S': 19, 'T': 20, 'U': 21, 'V': 22, 'W': 23, 'X': 24, 'Y': 25, 'Z': 26}
In [ ]:
word = 'Animal'
word_list = list(word.upper())
print(word_list)
['A', 'N', 'I', 'M', 'A', 'L']
In [ ]:
sum = 0
for w in word_list:
sum += alphabet[w]
print(sum)
50
Position_sum Function¶
this function will print the sum of the position of the letter in the alphabet list
In [ ]:
def position_sum(word):
word_list = list(word.upper())
sum = 0
for w in word_list:
sum += alphabet[w]
return sum
In [ ]:
position_sum('Mule')
Out[ ]:
51
In [ ]:
position_sum('LUme')
Out[ ]:
51
In [ ]:
position_sum("Mamun")
Out[ ]:
62
In [ ]:
position_sum("Animal")
Out[ ]:
50
In [ ]:
RELATED POSTS
View all