Skip to content

Instantly share code, notes, and snippets.

View gajeshbhat's full-sized avatar
🎯
Focusing

Gajesh Bhat gajeshbhat

🎯
Focusing
View GitHub Profile
@gajeshbhat
gajeshbhat / strToInt.py
Last active October 31, 2023 19:41
Convert k to Integer thousand Python.
def convert_str_to_number(x):
total_stars = 0
num_map = {'K':1000, 'M':1000000, 'B':1000000000}
if x.isdigit():
total_stars = int(x)
else:
if len(x) > 1:
total_stars = float(x[:-1]) * num_map.get(x[-1].upper(), 1)
return int(total_stars)