Python Forum
Create variable and list dynamically
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create variable and list dynamically
#3
(Jan-25-2021, 10:16 PM)bowlofred Wrote: Don't create them as separate variables in your namespace. Instead assign the variables to a collection, and pull out the values as needed. cirq.LineQubit.range(number) is already returning a list. Your assignment is just unpacking it into separate variables.


Instead consider:
number = 3
all_qbits = cirq.LineQubit.range(number)
print (all_qbits)
Output:
[cirq.LineQubit(0), cirq.LineQubit(1), cirq.LineQubit(2)]

Thanks it is true! But it could be nice to know logic. Because I also do following script dynalmically:
If I have 1 variable, it will be
a =kron(unitary(rz(qbt[0]))) 
If I have 2 vaarible, it will be
a = kron(unitary(rz(qt[0])),unitary(rz(qbt[1]))) 
and if I have 10, it will go...

HOw can I do it automatically?
Reply


Messages In This Thread
Create variable and list dynamically - by quest_ - Jan-25-2021, 09:59 PM
RE: Create variable and list dynamically - by quest_ - Jan-25-2021, 10:47 PM

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 2,132 Nov-07-2023, 09:49 AM
Last Post: buran
  Delete strings from a list to create a new only number list Dvdscot 8 1,729 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,657 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
  loop (create variable where name is dependent on another variable) brianhclo 1 1,207 Aug-05-2022, 07:46 AM
Last Post: bowlofred
  Split string using variable found in a list japo85 2 1,386 Jul-11-2022, 08:52 AM
Last Post: japo85
  how to easily create a list of already existing item CompleteNewb 15 3,839 Jan-06-2022, 12:48 AM
Last Post: CompleteNewb
  An IF statement with a List variable dedesssse 3 8,621 Jul-08-2021, 05:58 PM
Last Post: perfringo
  Create SQLite columns from a list or tuple? snakes 6 8,996 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,919 Jan-21-2021, 02:49 AM
Last Post: Johno
Question Matching variable to a list index Gilush 17 6,107 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