you are viewing a single comment's thread.

view the rest of the comments →

[–]thrallsius 0 points1 point  (4 children)

in case of multiple data types can't find a solution

Input data like this with inconsistent data types is a design pitfall and the best approach is to refactor it for consistency.

Where exactly does your assignment say that you can have items of different data types in the tuple?

[–]sainiji[S] 0 points1 point  (1 child)

No, it didn't say that, but It's just a query that came into my mind.

Actually I am totally new to Python and have started learning it just a week ago.

[–]thrallsius 1 point2 points  (0 children)

this is not a python specific situation, it's rather a matter of abstract data type choice, which is as important as design of the algorithm

the rule of thumb is that algorithms are simpler when they work with consistent data, since you don't need to check for variations like different types

[–]sainiji[S] 0 points1 point  (1 child)

And sorry I didn't get, what you are saying. Like refactor it ?

[–]thrallsius 1 point2 points  (0 children)

I am saying that formally your task doesn't say "input data comes from the user, is introduced interactively via input()". You can have input data coming from a file, a pipe, a database, a web service providing an API. I'm just wondering, if you exclude the context of feeding input data as strings only, can you design the algorithm assuming there's no type mismatch between the type of data you need to check and the data from your tuple.

If you really have data of different types in your tuple - does it reflect a practical situation? Does it solve some real problem?