Python Forum
Fastest Way to declare this list.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fastest Way to declare this list.
#1
I need to declare a list (a "matrix", in fact) by inserting new 2-dimensional lists into it, and i´m using append for that (code below):

M = []
for i in range (n): M.append([int(i) for i in input().split()])
Is there a quicker way to do this?
Reply
#2
Can you show an example of the input and the result list?
Reply
#3
[list(map(int, input().split())) for _ in range(n)]
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Fastest way tkinter Quatrixouuu 2 379 Feb-19-2024, 07:20 AM
Last Post: Danishhafeez
  What is the fastest way to get all the frames from a video file? glorsh66 3 1,049 May-26-2023, 04:41 AM
Last Post: Gribouillis
  Fastest Way of Writing/Reading Data JamesA 1 2,179 Jul-27-2021, 03:52 PM
Last Post: Larz60+
  Fastest Method for Querying SQL Server with Python Pandas BuJayBelvin 7 6,843 Aug-02-2020, 06:21 PM
Last Post: jefsummers
  Fastest dict/map method when 'key' is already a hash? tasket 6 3,965 Apr-20-2019, 06:40 PM
Last Post: tasket
  fastest way to record values between quotes paul18fr 5 3,269 Apr-15-2019, 01:51 PM
Last Post: snippsat
  How to declare a dynamic class 'header' Alfalfa 3 2,928 Sep-11-2018, 02:28 PM
Last Post: Alfalfa
  How to declare TextBlob var 3115Tech 2 2,713 Apr-21-2018, 07:04 PM
Last Post: 3115Tech

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020