Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
making it be a list of it
#8
def make_list(it):
    return it if isinstance(it, (list, tuple)) else [it,]
    
print(make_list([1,2,3]))
print(make_list('some string'))
Output:
[1, 2, 3] ['some string']
Reply


Messages In This Thread
making it be a list of it - by Skaperen - Mar-18-2018, 02:33 AM
RE: making it be a list of it - by Gribouillis - Mar-18-2018, 10:48 PM
RE: making it be a list of it - by DeaD_EyE - Mar-19-2018, 09:18 AM
RE: making it be a list of it - by wavic - Mar-19-2018, 08:54 AM
RE: making it be a list of it - by buran - Mar-19-2018, 09:11 AM
RE: making it be a list of it - by Gribouillis - Mar-19-2018, 09:47 AM
RE: making it be a list of it - by Skaperen - Mar-22-2018, 04:12 AM
RE: making it be a list of it - by buran - Mar-22-2018, 01:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Making a copy list in a function RuyCab 1 1,862 Jul-11-2021, 02:06 PM
Last Post: Yoriz
  making list in looping a dictionary glennford49 9 3,724 Jun-25-2020, 03:23 PM
Last Post: ndc85430
  making the code easier, list comprehension go127a 2 2,124 May-26-2019, 06:19 PM
Last Post: Gribouillis
  Making list empty after return in function dan789 10 5,957 Nov-24-2018, 11:54 PM
Last Post: micseydel
  Making a number list in a .txt file kwak86 13 6,357 Sep-16-2018, 09:54 PM
Last Post: kwak86

Forum Jump:

User Panel Messages

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