+ 3
What's with this syntax?
msg:str = "malayalam"; used:str = ""; i:int; for i in range(len(msg)): tmp:str = msg[i]; if (tmp not in used): used += tmp; print(tmp,":", end = ""); j: int; count:int = 0; for j in range(len(msg)): if (tmp == msg[j]): count += 1; print(count); here, even if i replace all the "str" with "float" the output doesn't change. so why was this implemented in the first case?
3 Respostas
+ 7
Str is just a hint but finally we have duck typing.
The value determines the type.
+ 6
Lothar oh those ☕
They must do 🧠 yoga when they 🐍 🐍 .
No semicolon, type anarchy....
A cultural shock 😲 😳 😐 😑
+ 5
Harsha S ,
just some comments to the code:
- we don't need to use semicolons at the end of the lines
- the task can be also be done by using the string method count() and a variable that indicates if a character is already seen / counted or not:
msg = "malayalam"
seen = ''
for char in msg:
if char not in seen:
print(char, msg.count(char))
seen += char