Python Forum
Using function argument in lists comprehension.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using function argument in lists comprehension.
#1
def nb_dig(n,d):
    r = [n**2 for n in range(1,n)]
    digz = [d for d in r]
    print(r,digz)
nb_dig(10,1)
Output:
>>>[1, 4, 9, 16, 25, 36, 49, 64, 81] [1, 4, 9, 16, 25, 36, 49, 64, 81]
So, I want 'd' to be a string value, telling me how many times certain number occurs in the results, but instead of it I get some bs. Why the damn 'd' in digz is not imported from the function parameters?
Reply


Messages In This Thread
Using function argument in lists comprehension. - by blackknite - Apr-23-2019, 07:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  mutable argument in function definition akbarza 1 521 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  Using list comprehension with 'yield' in function tester_V 5 1,324 Apr-02-2023, 06:31 PM
Last Post: tester_V
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,144 Dec-25-2022, 03:00 PM
Last Post: askfriends
  i want to use type= as a function/method keyword argument Skaperen 9 1,969 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  Use ranking function for different lists klatlap 6 2,061 Feb-15-2022, 11:31 PM
Last Post: klatlap
  Regex - Pass Flags as a function argument? muzikman 6 3,679 Sep-06-2021, 03:43 PM
Last Post: muzikman
  Pop function for lists jamesaarr 8 2,710 Aug-26-2021, 06:40 PM
Last Post: ndc85430
  How to invoke a function with return statement in list comprehension? maiya 4 2,919 Jul-17-2021, 04:30 PM
Last Post: maiya
  How to use a tuple as an argument of a function zarox 5 3,706 Nov-14-2020, 08:02 PM
Last Post: buran
  calling a function and argument in an input phillup7 3 2,651 Oct-25-2020, 02:12 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

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