Python Forum
Defining multiple functions in the same def process
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Defining multiple functions in the same def process
#6
(Aug-09-2020, 05:13 PM)ndc85430 Wrote: map takes a function as its first argument and applies it to each item of the iterable passed as its second argument. In the two examples, I pass in two different functions: one that doubles the argument that I use with the list of ints and one that turns its argument to uppercase, which I use with the list of strings.

Thanks, it's useful to recall this as I will do a lot of list calculation. I'll see how that can simplify my clumsy codes but currently it would be great if I have a way to define multiple functions within the same def process.

(Aug-09-2020, 05:18 PM)Yoriz Wrote: I'm not quite sure what you are after but maybe your better of with a class ?

Seems to be more like a programmer's work but I would still need to assign something to an output each time before getting the ratio and index. I will use the function a lot so it would add up the work. Besides that also means I cannot maintain the structure of line 5 of a higher function I showed earlier, since the ratio still cannot be just called up as a function.

def maxexternalratio(a, b, yr):
    Etemp = []
    for i in range(len(a)):
        for j in range(len(a)):
             Etemp.append(external(a, b, a[i], b[j], yr)['ratio'])
    return max(Etemp)
If so I think I'd rather define two functions separately with nearly identical codes although that would be clumsy and obviously amateur.
Reply


Messages In This Thread
RE: Defining multiple functions in the same def process - by sparkt - Aug-09-2020, 06:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Defining Functions theturtleking 4 2,851 Dec-07-2021, 06:45 PM
Last Post: deanhystad
  Run multiple process using subprocess Shiri 3 3,902 Nov-28-2021, 10:58 AM
Last Post: ghoul
  Process multiple pdf files Spartan314 1 1,348 Oct-27-2021, 10:46 PM
Last Post: Larz60+
  How to call multiple functions sequentially Mayo 2 9,452 Jan-06-2021, 07:37 PM
Last Post: Mayo
Question trouble with functions "def", calling/defining them Duck_Boom 13 4,441 Oct-21-2020, 03:50 AM
Last Post: Duck_Boom
  Multiple lambda functions in zipped list not executing psolar 0 1,618 Feb-13-2020, 12:53 PM
Last Post: psolar
  naming images adding to number within multiple functions Bmart6969 0 1,939 Oct-09-2019, 10:11 PM
Last Post: Bmart6969
  How to sharing object between multiple process from main process using Pipe Subrata 1 3,691 Sep-03-2019, 09:49 PM
Last Post: woooee
  Defining functions TommyAutomagically 1 1,896 Apr-25-2019, 06:33 PM
Last Post: Yoriz
  Multiple process access to a serial port mkonnov 0 3,079 Apr-14-2019, 12:42 PM
Last Post: mkonnov

Forum Jump:

User Panel Messages

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