Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
2D list creation
#1
Hello. How can be created a 2D list in a loop starting from 1 to 9:
[[1,2,3],
[4,5,6],
[7,8,9]]
Thanks beforehand.
Reply
#2
what have you tried? Post your code in code tags
Reply
#3
Hello. I got it :)
[[1+i+3*j for i in range(3)] for j in range(3)]

[[1+i+3*j for i in range(3)] for j in range(3)]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  List Creation and Position of Continue Statement In Regular Expression Code new_coder_231013 3 1,660 Jun-15-2022, 12:00 PM
Last Post: new_coder_231013
  List Creation sunnyarora 3 2,461 Mar-15-2019, 11:05 PM
Last Post: farhan275
  List creation and return in Function leoahum 3 2,413 Mar-04-2019, 04:45 PM
Last Post: leoahum

Forum Jump:

User Panel Messages

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