Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Columns in a table
#1
Hi, I'm looking for switching two columns in a table. I made a function , but I doon't know the syntax of an array switching in python . Could you guys help me please? Thx
def changeColumns():
    a = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [4, 5, 6, 7, 8, 9, 1, 2, 3], [7, 8, 9, 1, 2, 3, 4, 5, 6], [2, 3, 1, 5, 6, 4, 8, 9, 7], [5, 6, 4, 8, 9, 7, 2, 3, 1],[8, 9, 7, 2, 3, 1, 5, 6, 4], [3, 1, 2, 6, 4, 5, 9, 7, 8], [6, 4, 5, 9, 7, 8, 3, 1, 2], [9, 7, 8, 3, 1, 2, 6, 4, 5]]
    a[1,2,3,4,5,6,7,8,9][0],a[1,2,3,4,5,6,7,8,9][1]= a[1,2,3,4,5,6,7,8,9][1],a[1,2,3,4,5,6,7,8,9][0] #This is what i want to fix
    for i in range(len(a)):
        for j in range(len(a[i])):
            print(a[i][j], end=' ')
        print()
Reply


Messages In This Thread
Columns in a table - by Reldaing - Nov-19-2019, 09:13 PM
RE: Columns in a table - by jefsummers - Nov-19-2019, 09:31 PM
RE: Columns in a table - by Gribouillis - Nov-19-2019, 09:47 PM
RE: Columns in a table - by Reldaing - Nov-19-2019, 09:48 PM
RE: Columns in a table - by jefsummers - Nov-19-2019, 09:51 PM
RE: Columns in a table - by Reldaing - Nov-19-2019, 09:57 PM
RE: Columns in a table - by newbieAuggie2019 - Nov-20-2019, 07:39 AM
RE: Columns in a table - by ThomasL - Nov-20-2019, 12:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to create a table with different sizes of columns in MS word pepe 8 1,574 Dec-08-2023, 07:31 PM
Last Post: Pedroski55
  Sum the values in a pandas pivot table specific columns klllmmm 1 4,644 Nov-19-2021, 04:43 PM
Last Post: klllmmm
  SaltStack: MySQL returner save less data into Database table columns xtc14 2 2,175 Jul-02-2021, 02:19 PM
Last Post: xtc14
  Printing lists in a table, rows and columns randy_shooflay 6 6,319 Sep-05-2018, 07:59 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

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