Python Forum
Create variable and list dynamically
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create variable and list dynamically
#11
The examples I gave showed kron_argument_list() takes an integer as the argument. You're giving a list.

If you want to pass in the actual qbts, that's fine, but you'd have to change the function. The one I wrote just takes an integer and then makes the calls to create them.
quest_ likes this post
Reply
#12
(Jan-26-2021, 06:47 PM)nilamo Wrote:
(Jan-26-2021, 06:34 PM)quest_ Wrote: Apologize but I did not understand anyhting. Why are we seeing "spam foo 3" instead of "spam foo" when we run "show(*items)"

Because show() is always printing a, b, and c. The list that was expanded only had 2 elements, so only a and b had values coming from the list, while c still had it's default value as defined in the argument list: def show(a=1, b=2, c=3):



Quote:
a = kron(*kron_argument_list([i for i in range(qbt)]))
I have this error:
Error:
TypeError: 'tuple' object cannot be interpreted as an integer
What value does qbt have? I think the error is coming from range(qbt), and that qbt is a tuple at that point.
Oh I understood thanks !
I just confused the name of list sorry it is now working!
Reply
#13
(Jan-26-2021, 06:49 PM)bowlofred Wrote: The examples I gave showed kron_argument_list() takes an integer as the argument. You're giving a list.

If you want to pass in the actual qbts, that's fine, but you'd have to change the function. The one I wrote just takes an integer and then makes the calls to create them.

I noticed that. I changed the input of function and it is now ok
Thanks you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to create a variable only for use inside the scope of a while loop? Radical 10 1,747 Nov-07-2023, 09:49 AM
Last Post: buran
  Delete strings from a list to create a new only number list Dvdscot 8 1,547 May-01-2023, 09:06 PM
Last Post: deanhystad
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 1,528 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
  loop (create variable where name is dependent on another variable) brianhclo 1 1,145 Aug-05-2022, 07:46 AM
Last Post: bowlofred
  Split string using variable found in a list japo85 2 1,306 Jul-11-2022, 08:52 AM
Last Post: japo85
  how to easily create a list of already existing item CompleteNewb 15 3,573 Jan-06-2022, 12:48 AM
Last Post: CompleteNewb
  An IF statement with a List variable dedesssse 3 8,299 Jul-08-2021, 05:58 PM
Last Post: perfringo
  Create SQLite columns from a list or tuple? snakes 6 8,731 May-04-2021, 12:06 PM
Last Post: snakes
  How do I get the in3.Client() to create a variable with attributes? (in3 pypi pckge) Johno 2 1,864 Jan-21-2021, 02:49 AM
Last Post: Johno
Question Matching variable to a list index Gilush 17 5,916 Nov-30-2020, 01:06 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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