Python Forum
Can I use a sublist as an argument in python?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can I use a sublist as an argument in python?
#1
I have a nested list:

city = [['house', 'street', 'park'], ['car', 'bike', 'train']]
Now I want to define a function what takes the first sublist of city as the input (argument) with the variable 'part', what takes the value 0 or 1 (depending on if I want to use the first or the second sublist:

def sublist(city[part]):
The editor returns the error:

def sublist(city[part]):
                ^
SyntaxError: invalid syntax 
Is it possible to use a sublist as an argument in python? If yes, how can I do it?
Reply


Messages In This Thread
Can I use a sublist as an argument in python? - by MartinBerlin - Aug-25-2018, 10:06 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Sublist/ Subarray into string Python SantiagoPB 2 2,169 Apr-23-2021, 07:03 PM
Last Post: SantiagoPB
  SyntaxError: positional argument follows keyword argument syd_jat 3 5,886 Mar-03-2020, 08:34 AM
Last Post: buran
  List of objects with sublist medatib531 4 2,372 Mar-01-2020, 06:16 PM
Last Post: buran
  Insert into sublist if sublist is not having same no of records. parthi1705 10 4,596 May-28-2019, 12:01 PM
Last Post: perfringo
  Split List and Sublist from Pyodbc parthi1705 1 2,258 May-05-2019, 10:44 AM
Last Post: Larz60+
  merging sublist into single list in python abhishek8singhai 8 9,605 Mar-22-2019, 11: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