Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Select a part of an element of a list with Index
#1
I've created a list with a for loop and got elements with many elements... How can I make this easier?

    cmc = []

    CYC1 = cmc[0]

    CYC2 = cmc[1]

    CYC3 = cmc[2]

    CYC4 = cmc[3]

    c = []

    c.append(CYC1[67:79])

    c.append(CYC2[67:79])

    c.append(CYC3[67:79])

    print(c)
you don't need the intermediate cyc variables:
for i in range(4):
    c.append(cmc[i][67:79])
Larz60+ wrote Aug-09-2019, 11:15 AM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  can't remove element from a list yokaso 6 116 Nov-06-2019, 03:11 PM
Last Post: yokaso
  get the one element from 1-list or 1-set Skaperen 1 61 Nov-05-2019, 11:50 PM
Last Post: Gribouillis
  IndexError: List index out of range issue Adem 1 153 Nov-01-2019, 10:47 PM
Last Post: ichabod801
  IndexError: list index out of range bug? CaptainCsaba 4 202 Oct-18-2019, 12:38 PM
Last Post: CaptainCsaba
  returns index of list if contains a word zarize 0 121 Sep-09-2019, 09:29 AM
Last Post: zarize
  MAWS.py PRGM:IndexError: list index out of range bcramer 0 125 Aug-28-2019, 04:45 PM
Last Post: bcramer
  List of dictionaries: use key-value instead of index? dn237 6 520 Jun-03-2019, 05:52 PM
Last Post: Yoriz
  Preventing: IndexError: list index out of range PappaBear 1 1,981 Jun-03-2019, 05:50 PM
Last Post: SheeppOSU
  json.load causing IndexError: list index out of range WallyZ 5 622 May-20-2019, 01:11 PM
Last Post: WallyZ
  Replace a list or string element with a random one.. pianistseb 3 311 May-09-2019, 08:24 AM
Last Post: buran

Forum Jump:


Users browsing this thread: 1 Guest(s)