Python Forum
mutable values to string items?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
mutable values to string items?
#5
(Aug-21-2022, 08:06 PM)fozz Wrote:
channels = [
    ['#channel1', 0],
    ['#channel2', 0],
    ['#channel3', 0],
]

Assigning the first element from channels to a name:
first = channels[0]
Assigning a list to the first element of the list channels:
channels[0] = ["channel33", 33]
If you do not want to use integer indices, then use a dict.
channels = {
    '#channel1': 0,
    '#channel2': 0,
    '#channel3': 0,
}

channels['#channel4'] = 33
channels['#channel1'] = 1

for name, value in channels.items():
    print(name, "->", value)
Output:
#channel1 -> 1 #channel2 -> 0 #channel3 -> 0 #channel4 -> 33
Getting all values, but not the channels (keys of the dict):
print(list(channels.values()))
Output:
[1, 0, 0, 33]
If you use for your program the wrong data structures, then handling the data is very complicated.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
mutable values to string items? - by fozz - Aug-21-2022, 08:06 PM
RE: mutable values to string items? - by snippsat - Aug-21-2022, 08:58 PM
RE: mutable values to string items? - by rob101 - Aug-21-2022, 09:02 PM
RE: mutable values to string items? - by deanhystad - Aug-22-2022, 02:43 AM
RE: mutable values to string items? - by DeaD_EyE - Aug-22-2022, 07:58 AM
RE: mutable values to string items? - by fozz - Aug-22-2022, 04:18 PM
RE: mutable values to string items? - by fozz - Aug-29-2022, 02:24 PM
RE: mutable values to string items? - by deanhystad - Aug-29-2022, 07:33 PM
RE: mutable values to string items? - by fozz - Aug-29-2022, 09:01 PM
RE: mutable values to string items? - by fozz - Aug-29-2022, 08:43 PM
RE: mutable values to string items? - by deanhystad - Aug-30-2022, 05:25 AM
RE: mutable values to string items? - by deanhystad - Aug-30-2022, 03:20 PM
RE: mutable values to string items? - by fozz - Aug-30-2022, 06:37 PM
RE: mutable values to string items? - by deanhystad - Aug-30-2022, 07:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  using mutable in function defintion as optional paramter akbarza 8 667 Apr-27-2024, 09:59 PM
Last Post: snippsat
  mutable argument in function definition akbarza 1 564 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  Trying to compare string values in an if statement israelsattleen 1 619 Jul-08-2023, 03:49 PM
Last Post: deanhystad
  Getting rid of old string values Pedroski55 3 1,108 Oct-11-2022, 10:56 PM
Last Post: Pedroski55
  Parse String between 2 Delimiters and add as single list items lastyle 5 3,524 Apr-11-2021, 11:03 PM
Last Post: lastyle
  "'DataFrame' objects are mutable, thus they cannot be hashed" Mark17 1 6,970 Dec-25-2020, 02:31 AM
Last Post: tinh
  Mutable Strings millpond 3 2,705 Aug-24-2020, 08:42 AM
Last Post: millpond
  Function parameters and values as string infobound 1 1,823 Jul-24-2020, 04:28 AM
Last Post: scidam
  xml.etree.ElementTree extract string values matthias100 2 5,163 Jul-12-2020, 06:02 PM
Last Post: snippsat
  What is the meaning of mutable data type? qliu 3 3,076 Apr-17-2020, 07:20 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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