Please ignore secret bonuses. Secret tests do NOT award bonus. Max hw grade is 30+2 bonus efficiency

Do you need help?

hw2 ignoring the whitespaces and tabs

G
Gülümser Aslı Kütük (310 points)
2 4 6
in HW1 optional by (310 points)
hey there. Can I ignore taking whitespaces and tabs into the account when sorting according to unicode by saying:

ord(' ')==0?
355 views

4 Answers

GabrielAlexandru (7760 points)
2 4 29
by (7.8k points)
ord(' ') will never be equals to 0 as whitespace is returned as 32. You can convert it in ord(' ') == 32 for whitespace (other number for tabs, but I don't remember which is).
Exyss (21510 points)
1 2 79
by (21.5k points)
ord("\t") should be equal to 9
G
Gülümser Aslı Kütük (310 points)
2 4 6
by (310 points)
Is there a way for me to ignore tabs and whitespaces without defining another function tho?
Excale (490 points)
0 0 6
by (490 points)

Python has a function that lets you replace a substring from a string in something else, you could use that to make your job easier (even better, there's a function that replaces characters only, it should be quicker). Be aware of how many times you use that though, if you use it too many times it will bring up execution time.

If you want to continue with your idea, why don't just compare the characters before applying ord? So you can verify that the character is space/tab doing char = " " or char = "\t", or just compare the ord like ord(char) = ord(" ") or ord(char) = ord("\t").

One last thing, if you need to sort the strings you have to use the "no-whitespace" strings, unless you make a function that sorts while ignoring whitespaces.

G
Gülümser Aslı Kütük (310 points)
2 4 6
by (310 points)
thank you so much!
gianluca5539 (9820 points)
4 6 44
by (9.8k points)
You can remove all spaces and tabs with a method. Think of replacing them with nothing.....
G
GuidoG93 (970 points)
6 9 13
by (970 points)
I don't think it would work, try looking for other functions like replace or strip...
G
Gülümser Aslı Kütük (310 points)
2 4 6
by (310 points)
ı'll try to do that thanks!
Luigi Pizza (6120 points)
14 20 65
by (6.1k points)
you can use also the filter function: As the name suggestes it takes away all elements from a list who don't respect a certain criteria, (you can also use a lambda function inside it).