Python Forum
Displaying list correspond to the column number
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Displaying list correspond to the column number
#9
(Apr-04-2021, 10:37 AM)ibreeden Wrote:
(Apr-04-2021, 10:02 AM)danlopek14q Wrote:
this is not correct
def all_list(listas,column = []): # this is wrong
for example:
def func(arr = []):
    print(arr)
    arr.append(2)

func() # each time this function is called, the default arg will change
func()
func()
func()
Output:
[] [2] [2, 2] [2, 2, 2]
The correct code with default list should be:
Choice 1:
def func(arr = None):
    if arr == None:
        arr = []
    return arr

print(func([1, 2, 3, 4]))
Choice 2:
def func(*args):
    arr = list(args)
    return arr

print(func(1, 2, 3, 4))
Reply


Messages In This Thread
RE: Displaying list correspond to the column number - by naughtyCat - Aug-27-2021, 04:24 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  list digit into number Voldyy 2 1,642 Jul-10-2022, 06:13 PM
Last Post: deanhystad
  How to convert every even number in a list to odd? Bruizeh 4 3,945 Aug-27-2021, 03:04 AM
Last Post: naughtyCat
  Get the biggest number from a two dimensional list rs74 13 4,322 Aug-09-2020, 04:02 PM
Last Post: deanhystad
  How can I print the number of unique elements in a list? AnOddGirl 5 3,428 Mar-24-2020, 05:47 AM
Last Post: AnOddGirl
  Multiplying number in a list in an order pythoneer 12 6,859 Mar-23-2018, 08:21 PM
Last Post: buran
  Displaying number of currency danellapotter 3 2,892 Jan-16-2018, 07:58 PM
Last Post: buran
  adding a number to the list atux_null 4 4,010 Nov-06-2017, 07:01 PM
Last Post: gruntfutuk
  Displaying a long list with Rows and Columns ngr33n 5 11,244 Sep-21-2017, 10:17 PM
Last Post: ngr33n
  sorted list not displaying Crackity 6 5,278 Jul-18-2017, 12:50 PM
Last Post: sparkz_alot
  Determine if a list contains a specific number of an item flannel_man 3 5,035 Nov-12-2016, 04:46 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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