why I cannot use max() function in this case? [duplicate]
2024/11/18 20:22:03
n,m,k=map(int, input().split())
data=list(map(int, input().split()))for i in data:print(i)
#consequence=2 3 4 5 6
for i in data:print(max(i))
#consequence= TypeError: 'int' object is not iterable
If int is iterable, then why I can use int in for loop? Why I cannot use max() function in this case?
Answer
You can use max(x) like this:
data = [1,2,3,4,5]
max(m) # result 5
Int is not iterable but list is iterable. If you iterate you iterate trought list in for loop. How you use a for loop to find maximum doesnt make sense. Beacuse for every particular intiger you try to find a maximum. You can use this method as input of list.
I am using cloudkitty which is rating module in OpenStacks.But here question is regarding the SQLAlchemy and Python.I am new to SQLAlchemy.I need to fetch some details from a table using a API call.So …
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.Closed 10 years ago.Questions asking for code must demonstrate a minimal understanding of the proble…
I found this code to connect to remote sftp server with the help of username ,password and host but i also need to include the port number, can any one let em know how to include the port number in thi…
Im trying to retrieve the PAN of a smart card using pyscard in Python. What I have done so far is to connect to the reader and to retrieve various information about the reader and the card... but I can…
My laptop keyboard has a bug and it sometimes presses the number 5 randomly so i tried many things and they didnt work, I tried programming a code that can stop it but i couldnt because i am a beginner…
trying to write a Python function:
def compare_lengths(x, y, z)
which takes as arguments three arrays and checks their lengths and returns them as a triple in order of length.
For example, if the funct…
This question already has answers here:Split string every nth character(21 answers)How to iterate over a list in chunks(40 answers)Closed 10 years ago.Does anyone know if its possible in python to spli…
How to change a .las file into a .csv file? Have been trying myself but no luck no far. I am just looking for something decently short that will save some time when I have to convert big .olas files i…
Note: I have solve this problem as per below:I can use to_csv to write to stdout in python / pandas. Something like this works fine:final_df.to_csv(sys.stdout, index=False)I would like to read in an a…