Skip to content

Commit 9be8e92

Browse files
authored
Create main.py
1 parent aef8611 commit 9be8e92

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Encoding/main.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
char_list:list = ["a", "g", "f", "b", "c", "e", "d"]
2+
3+
def label_encoding(char_list:list)->list:
4+
'''
5+
This function is used for encoding which converts text data into numeric data based on the alphabetic order!
6+
'''
7+
8+
sorted_char_list:list = sorted(char_list)
9+
encoded:list = []
10+
11+
for ch in char_list:
12+
index = sorted_char_list.index(ch)
13+
encoded.append(index)
14+
15+
return encoded
16+
17+
print(label_encoding(char_list))
18+
19+
def ordinal_encoding(char_list:list)->list:
20+
'''
21+
This function is used for encoding which converts text data into numeric data based on the alphabetic order!
22+
'''
23+
# assuming that the passed list is the order in which the user wants encoding!!
24+
encoded:list = []
25+
26+
for ch in char_list:
27+
index = char_list.index(ch)
28+
encoded.append(index)
29+
30+
return encoded
31+
32+
print(ordinal_encoding(char_list))

0 commit comments

Comments
 (0)