Recently, I was training on some libraries in Python 3 and I noticed that the most difficult was not the questions, but the way you are going to take your input and present your output. 






So, I'd like to show some ways I've learned and it may help you, too.
1. Lists:
Taking separated input like:
2 3 4 5 6 7 and put them into the list can be done by map function:
a = list (map(int, input().split()))
or
a = tuple(map(int, input().split()))
same if inputs are float
- I will say that you don't need to do the same if the inputs were string! because the string is easily added into a list like:
a = input().split() < it put them directly into a list>
___________________________
If you'll take 2 separated numbers and you are going to use just one of them, so:
you may use one of those ways:
n, m = list(map(int, input().split()))
and use them by their names n, m, and so on.
or you can use:
p = input().split()
them if you wanna use the first number you take it as int(p[0])
__________________________
Arrays:
Look at the line no.4 wt is between [] is called list comprehension (search about the syntax)
By this way, I can take inputs like the following and put it into an array (use NumPy because python doesn't support matrices)
Sometimes, we use *map(int, input().split()) but with * and without a list when we directly put the input into a function. So, I think we use * when doing a function inside a function.
________________________
OutPuts
I don't have any specific notices on outputs unless Formate
"{}, Is my age".formate(age)
when age is a function when "--" is a string. we may put some details like:
Here, we put the types and significance of the represented values.
______________________________
One line code:
Yes, we like to write the fewest number of lines into the notepad. If we want to print more than a line of outputs, how could we achieve that?
It is so easy use:
sep = '\n' after putting all your printed function separated by commas, ex:
print(n, m, k, sep = '\n')
out put =
n
m
k
(with values of course)
______________________________
Also a way with Numpy:
numpy.set_printoptions(legacy='some numbers') or numpy.set_printoptions(sign=' ')
and there are many arguments in this function. It needs to be searched. So, friends!
I am waiting for your search results. Put the links in the comments, I'd like to check them all.
This is the first comment from you, guys:
Very good comments. Sometimes, I just think about the matter from the contest's view as hackerrank makes me always think.
Comments
Post a Comment