Python Forum
Printing lists in a table, rows and columns
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Printing lists in a table, rows and columns
#7
In previous posts there was no random.shuffle to be seen.

My suggestion was based on this piece of code:

numbers = [0,1,2,3,4,5,6,7,8,9]
...
for num in numbers:
    print(num, end='\t')
Which can be expressed:

for num in range(10):
    print(num, end='\t')
Regarding random.shuffle: best way is to start with built-in help:

>>> import random
>>> help(random.shuffle)
Help on method shuffle in module random:

shuffle(x, random=None) method of random.Random instance
    Shuffle list x in place, and return None.
    
    Optional argument random is a 0-argument function returning a
    random float in [0.0, 1.0); if it is the default None, the
    standard random.random will be used.
(END)
Your code will not work, it doesn't matter whether you use for num in numbers or for num in range(10), argument must be a list.

>>> import random
>>> r = list(range(10))
>>> random.shuffle(r)
>>> r
[1, 8, 2, 5, 4, 9, 0, 6, 7, 3]
>>> random.shuffle(r)
>>> r
[0, 6, 5, 1, 4, 7, 9, 2, 3, 8]
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: Printing lists in a table, rows and columns - by perfringo - Sep-05-2018, 07:59 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 2,084 Dec-08-2023, 07:31 PM
Last Post: Pedroski55
  python script for inserting rows into hbase table lravikumarvsp 7 7,416 Mar-24-2023, 04:44 AM
Last Post: parth_botadara
  Converting a json file to a dataframe with rows and columns eyavuz21 13 5,455 Jan-29-2023, 03:59 PM
Last Post: eyavuz21
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 2,187 Dec-12-2022, 08:22 PM
Last Post: jh67
  Check DataFrames with different sorting in columns and rows Foxyskippy 0 858 Nov-19-2022, 07:49 AM
Last Post: Foxyskippy
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,713 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  Sum the values in a pandas pivot table specific columns klllmmm 1 4,874 Nov-19-2021, 04:43 PM
Last Post: klllmmm
  Dynamically Add rows to table TommyAutomagically 1 2,238 Nov-04-2021, 10:59 PM
Last Post: TommyAutomagically
  making variables in my columns and rows in python kronhamilton 2 1,767 Oct-31-2021, 10:38 AM
Last Post: snippsat
  rows from sql query need to write to a file as columns sjcsvatt 6 2,640 Oct-09-2021, 12:45 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

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