Python Forum
Why do I have to repeat items in list slices in order to make this work?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why do I have to repeat items in list slices in order to make this work?
#4
I think indexing is best avoided when possible.
distros = {
    "debian": ("Ubuntu", "Mint", "Kali"),
    "Red Hat": ("Fedora", "CentOS", "Oracle"),
    "slackware": ("Mageia", "KateOS", "Slackintosh"),
}

for vendor in distros:
    for distro in distros[vendor]:
        print(f"{distro} is a {vendor} distro.")
Output:
Kali is a debian distro. Fedora is a Red Hat distro. CentOS is a Red Hat distro. Oracle is a Red Hat distro. Mageia is a slackware distro. KateOS is a slackware distro. Slackintosh is a slackware distro.
Pythonica likes this post
Reply


Messages In This Thread
RE: Why do I have to repeat items in list slices in order to make this work? - by deanhystad - May-19-2023, 04:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Extending list doesn't work as expected mmhmjanssen 2 232 May-09-2024, 05:39 PM
Last Post: Pedroski55
  How to parse and group hierarchical list items from an unindented string in Python? ann23fr 0 246 Mar-27-2024, 01:16 PM
Last Post: ann23fr
  Copying the order of another list with identical values gohanhango 7 1,244 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  hi need help to make this code work correctly atulkul1985 5 883 Nov-20-2023, 04:38 PM
Last Post: deanhystad
  tuple indices must be integers or slices, not str cybertooth 16 11,998 Nov-02-2023, 01:20 PM
Last Post: brewer32
  newbie question - can't make code work tronic72 2 740 Oct-22-2023, 09:08 PM
Last Post: tronic72
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 1,316 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  Beginner: Code not work when longer list raiviscoding 2 881 May-19-2023, 11:19 AM
Last Post: deanhystad
  Response.json list indices must be integers or slices, not str [SOLVED] AlphaInc 4 6,600 Mar-24-2023, 08:34 AM
Last Post: fullytotal
  Finding combinations of list of items (30 or so) LynnS 1 921 Jan-25-2023, 02:57 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