Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

2d list comprehension python

[[float(c) for c in row] for row in data]
Comment

create 2d array python list comprehension

#by taking the user input
def main():
    #write your code here
    row = int(input())
    col  = int(input()
    
    #using the list comprehensions
    matrix = [[int(input())for j in range(col)]for j in range(row)]
    #display the matrix
    for i in range(row):
        for j in range(col):
            print(matrix[i][j],end=" ")
        print()

if __name__ == "__main__":
    main()
Comment

2d list comprehension python


[int(x) for line in data for x in line.split()]

Comment

PREVIOUS NEXT
Code Example
Python :: port 5432 failed: Connection timed out (0x0000274C/10060) Is the server running on that host and accepting TCP/IP connections? 
Python :: Python Program to Convert Decimal to Binary, Octal and Hexadecimal 
Python :: remove duplicates python 
Python :: how to create a fixed size empty array in python 
Python :: strptime 
Python :: python check if string is int 
Python :: django on_delete options 
Python :: python while not 
Python :: get column number in dataframe pandas 
Python :: left click pyautogui 
Python :: python remove none from dict 
Python :: python string match ignore case 
Python :: pathlib get extension 
Python :: how to print python 
Python :: n-largest and n-smallest in list in python 
Python :: python make sound when finished 
Python :: python longest word in string 
Python :: how to check if given number is binary in pytho 
Python :: df count zeros 
Python :: dataframe pandas to spark 
Python :: fastest clicker python 
Python :: pandas delete spaces 
Python :: how to hide turtle in python 
Python :: pycairo 
Python :: Conversion of number string to float in django 
Python :: pipenv with specific python version 
Python :: model checkpoint keras 
Python :: difference of two set in python 
Python :: logistic regression algorithm in python 
Python :: if found then stop the loop python 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =