Заменить элемент в списке в Python: полное руководство

| | | | |

–ï—Å—Ç—å —Ç—Ä–∏ —Å–ø–æ—Å–æ–±–∞ –∑–∞–º–µ–Ω–∏—Ç—å —ç–ª–µ–º–µ–Ω—Ç –≤ —Å–ø–∏—Å–∫–µ Python. –í—ã –º–æ–∂–µ—Ç–µ –∏—Å–ø–æ–ª—å–∑–æ–≤–∞—Ç—å –∏–Ω–¥–µ–∫—Å–∏—Ä–æ–≤–∞–Ω–∏–µ —Å–ø–∏—Å–∫–∞ –∏–ª–∏ —Ü–∏–∫–ª for –¥–ª—è –∑–∞–º–µ–Ω—ã —ç–ª–µ–º–µ–Ω—Ç–∞. –ï—Å–ª–∏ –≤—ã —Ö–æ—Ç–∏—Ç–µ —Å–æ–∑–¥–∞—Ç—å –Ω–æ–≤—ã–π —Å–ø–∏—Å–æ–∫ –Ω–∞ –æ—Å–Ω–æ–≤–µ —Å—É—â–µ—Å—Ç–≤—É—é—â–µ–≥–æ —Å–ø–∏—Å–∫–∞ –∏ –≤–Ω–µ—Å—Ç–∏ –∏–∑–º–µ–Ω–µ–Ω–∏—è, –≤—ã –º–æ–∂–µ—Ç–µ –∏—Å–ø–æ–ª—å–∑–æ–≤–∞—Ç—å –ø–æ–Ω–∏–º–∞–Ω–∏–µ —Å–ø–∏—Å–∫–∞.

–í—ã –º–æ–∂–µ—Ç–µ —Ä–µ—à–∏—Ç—å, —á—Ç–æ —Ö–æ—Ç–∏—Ç–µ –∏–∑–º–µ–Ω–∏—Ç—å –∑–Ω–∞—á–µ–Ω–∏–µ –≤ —Å–ø–∏—Å–∫–µ. –ü—Ä–µ–¥–ø–æ–ª–æ–∂–∏–º, –≤—ã —Å–æ–∑–¥–∞–µ—Ç–µ –º–µ–Ω—é –¥–ª—è —Ä–µ—Å—Ç–æ—Ä–∞–Ω–∞. –í—ã –º–æ–∂–µ—Ç–µ –∑–∞–º–µ—Ç–∏—Ç—å, —á—Ç–æ –Ω–µ–ø—Ä–∞–≤–∏–ª—å–Ω–æ –Ω–∞–ø–∏—Å–∞–ª–∏ –æ–¥–∏–Ω –∏–∑ –ø—É–Ω–∫—Ç–æ–≤ –º–µ–Ω—é. –ß—Ç–æ–±—ã –∏—Å–ø—Ä–∞–≤–∏—Ç—å —ç—Ç—É –æ—à–∏–±–∫—É, –≤–∞–º –Ω—É–∂–Ω–æ –±—É–¥–µ—Ç –∏–∑–º–µ–Ω–∏—Ç—å —Å—É—â–µ—Å—Ç–≤—É—é—â–∏–π —ç–ª–µ–º–µ–Ω—Ç –≤ —Å–ø–∏—Å–∫–µ.

Python Replace Item in List

–í—ã –º–æ–∂–µ—Ç–µ –∑–∞–º–µ–Ω–∏—Ç—å —ç–ª–µ–º–µ–Ω—Ç –≤ —Å–ø–∏—Å–∫–µ Python, –∏—Å–ø–æ–ª—å–∑—É—è —Ü–∏–∫–ª for, –∏–Ω–¥–µ–∫—Å–∏—Ä–æ–≤–∞–Ω–∏–µ —Å–ø–∏—Å–∫–∞ –∏–ª–∏ –ø–æ–Ω–∏–º–∞–Ω–∏–µ —Å–ø–∏—Å–∫–∞. –ü–µ—Ä–≤—ã–µ –¥–≤–∞ –º–µ—Ç–æ–¥–∞ –∏–∑–º–µ–Ω—è—é—Ç —Å—É—â–µ—Å—Ç–≤—É—é—â–∏–π —Å–ø–∏—Å–æ–∫, —Ç–æ–≥–¥–∞ –∫–∞–∫ –∞–Ω–∞–ª–∏–∑ —Å–ø–∏—Å–∫–∞ —Å–æ–∑–¥–∞–µ—Ç –Ω–æ–≤—ã–π —Å–ø–∏—Å–æ–∫ —Å —É–∫–∞–∑–∞–Ω–Ω—ã–º–∏ –∏–∑–º–µ–Ω–µ–Ω–∏—è–º–∏.

–ü–æ–¥–≤–µ–¥–µ–º –∏—Ç–æ–≥–∏ –∫–∞–∂–¥–æ–≥–æ –º–µ—Ç–æ–¥–∞:

  • –ò–Ω–¥–µ–∫—Å–∏—Ä–æ–≤–∞–Ω–∏–µ —Å–ø–∏—Å–∫–∞: –º—ã –∏—Å–ø–æ–ª—å–∑—É–µ–º –ø–æ—Ä—è–¥–∫–æ–≤—ã–π –Ω–æ–º–µ—Ä —ç–ª–µ–º–µ–Ω—Ç–∞ —Å–ø–∏—Å–∫–∞ –¥–ª—è –∏–∑–º–µ–Ω–µ–Ω–∏—è –∑–Ω–∞—á–µ–Ω–∏—è, —Å–≤—è–∑–∞–Ω–Ω–æ–≥–æ —Å —ç—Ç–∏–º —ç–ª–µ–º–µ–Ω—Ç–æ–º. –ó–Ω–∞–∫ —Ä–∞–≤–µ–Ω—Å—Ç–≤–∞ –∏—Å–ø–æ–ª—å–∑—É–µ—Ç—Å—è –¥–ª—è –∏–∑–º–µ–Ω–µ–Ω–∏—è –∑–Ω–∞—á–µ–Ω–∏—è –≤ —Å–ø–∏—Å–∫–µ.
  • –ü–æ–Ω–∏–º–∞–Ω–∏–µ —Å–ø–∏—Å–∫–∞: —Å–∏–Ω—Ç–∞–∫—Å–∏—Å –ø–æ–Ω–∏–º–∞–Ω–∏—è —Å–ø–∏—Å–∫–∞ —Å–æ–∑–¥–∞–µ—Ç –Ω–æ–≤—ã–π —Å–ø–∏—Å–æ–∫ –∏–∑ —Å—É—â–µ—Å—Ç–≤—É—é—â–µ–≥–æ. –í—ã –º–æ–∂–µ—Ç–µ —É–∫–∞–∑–∞—Ç—å —É—Å–ª–æ–≤–∏—è –≤ —Å–≤–æ–µ–º –ø–æ–Ω–∏–º–∞–Ω–∏–∏ —Å–ø–∏—Å–∫–∞, —á—Ç–æ–±—ã –æ–ø—Ä–µ–¥–µ–ª–∏—Ç—å –∑–Ω–∞—á–µ–Ω–∏—è –≤ –Ω–æ–≤–æ–º —Å–ø–∏—Å–∫–µ.
  • For Loop: —Ü–∏–∫–ª –≤—ã–ø–æ–ª–Ω—è–µ—Ç –∏—Ç–µ—Ä–∞—Ü–∏—é –ø–æ —ç–ª–µ–º–µ–Ω—Ç–∞–º –≤ —Å–ø–∏—Å–∫–µ. –í—ã –∏—Å–ø–æ–ª—å–∑—É–µ—Ç–µ –∏–Ω–¥–µ–∫—Å–∞—Ü–∏—é, —á—Ç–æ–±—ã –≤–Ω–µ—Å—Ç–∏ —Ñ–∞–∫—Ç–∏—á–µ—Å–∫–∏–µ –∏–∑–º–µ–Ω–µ–Ω–∏—è –≤ —Å–ø–∏—Å–æ–∫. –ú—ã –∏—Å–ø–æ–ª—å–∑—É–µ–º –º–µ—Ç–æ–¥ enumerate () –¥–ª—è —Å–æ–∑–¥–∞–Ω–∏—è –¥–≤—É—Ö —Å–ø–∏—Å–∫–æ–≤ –∏–Ω–¥–µ–∫—Å–æ–≤ –∏ –∑–Ω–∞—á–µ–Ω–∏–π, –ø–æ –∫–æ—Ç–æ—Ä—ã–º –º—ã –º–æ–∂–µ–º –≤—ã–ø–æ–ª–Ω—è—Ç—å –∏—Ç–µ—Ä–∞—Ü–∏—é.

–í —ç—Ç–æ–º —Ä—É–∫–æ–≤–æ–¥—Å—Ç–≤–µ –º—ã —Ä–∞—Å—Å–º–æ—Ç—Ä–∏–º –∫–∞–∂–¥—ã–π –∏–∑ —ç—Ç–∏—Ö –º–µ—Ç–æ–¥–æ–≤. –ú—ã —Ä–∞—Å—Å–º–æ—Ç—Ä–∏–º –ø—Ä–∏–º–µ—Ä –∫–∞–∂–¥–æ–≥–æ –∏–∑ –Ω–∏—Ö, —á—Ç–æ–±—ã –ø–æ–º–æ—á—å –≤–∞–º –Ω–∞—á–∞—Ç—å —Ä–∞–±–æ—Ç—É.

Python Replace Item in List: Using List Indexing

–°–∞–º—ã–π –ø—Ä–æ—Å—Ç–æ–π —Å–ø–æ—Å–æ–± –∑–∞–º–µ–Ω–∏—Ç—å —ç–ª–µ–º–µ–Ω—Ç –≤ —Å–ø–∏—Å–∫–µ - —ç—Ç–æ –∏—Å–ø–æ–ª—å–∑—É–π—Ç–µ —Å–∏–Ω—Ç–∞–∫—Å–∏—Å –∏–Ω–¥–µ–∫—Å–∞—Ü–∏–∏ Python . –ò–Ω–¥–µ–∫—Å–∏—Ä–æ–≤–∞–Ω–∏–µ –ø–æ–∑–≤–æ–ª—è–µ—Ç –≤—ã–±—Ä–∞—Ç—å —ç–ª–µ–º–µ–Ω—Ç –∏–ª–∏ –¥–∏–∞–ø–∞–∑–æ–Ω —ç–ª–µ–º–µ–Ω—Ç–æ–≤ –≤ —Å–ø–∏—Å–∫–µ. –° –ø–æ–º–æ—â—å—é –æ–ø–µ—Ä–∞—Ç–æ—Ä–∞ –ø—Ä–∏—Å–≤–∞–∏–≤–∞–Ω–∏—è –≤—ã –º–æ–∂–µ—Ç–µ –∏–∑–º–µ–Ω–∏—Ç—å –∑–Ω–∞—á–µ–Ω–∏–µ –≤ –∑–∞–¥–∞–Ω–Ω–æ–π –ø–æ–∑–∏—Ü–∏–∏ –≤ —Å–ø–∏—Å–∫–µ.

–ú—ã —Å–æ–∑–¥–∞–µ–º –ø—Ä–æ–≥—Ä–∞–º–º—É, –∫–æ—Ç–æ—Ä–∞—è —Ö—Ä–∞–Ω–∏—Ç –∏–Ω—Ñ–æ—Ä–º–∞—Ü–∏—é –æ —Ü–µ–Ω–∞—Ö –≤ –º–∞–≥–∞–∑–∏–Ω–µ –æ–¥–µ–∂–¥—ã. –¶–µ–Ω–∞ –ø–µ—Ä–≤–æ–≥–æ —Ç–æ–≤–∞—Ä–∞ –≤ –Ω–∞—à–µ–º —Å–ø–∏—Å–∫–µ –¥–æ–ª–∂–Ω–∞ –±—ã—Ç—å —É–≤–µ–ª–∏—á–µ–Ω–∞ –Ω–∞ 5 –¥–æ–ª–ª–∞—Ä–æ–≤. –î–ª—è —ç—Ç–æ–≥–æ , –º—ã –∏—Å–ø–æ–ª—å–∑—É–µ–º –∏–Ω–¥–µ–∫—Å–∏—Ä–æ–≤–∞–Ω–∏–µ —Å–ø–∏—Å–∫–æ–º.

–î–∞–≤–∞–π—Ç–µ –Ω–∞—á–Ω–µ–º —Å —Å–æ–∑–¥–∞–Ω–∏—è —Å–ø–∏—Å–∫–∞, –∫–æ—Ç–æ—Ä—ã–π —Å–æ–¥–µ—Ä–∂–∏—Ç —Ü–µ–Ω—ã –Ω–∞ –Ω–∞—à–∏ –ø—Ä–æ–¥—É–∫—Ç—ã:

81% —É—á–∞—Å—Ç–Ω–∏–∫–æ–≤ –∑–∞—è–≤–∏–ª–∏, —á—Ç–æ –æ–Ω–∏ —á—É–≤—Å—Ç–≤–æ–≤–∞–ª–∏ —Å–µ–±—è –±–æ–ª–µ–µ —É–≤–µ—Ä–µ–Ω–Ω—ã–º–∏ –≤ —Å–≤–æ–∏—Ö –ø–µ—Ä—Å–ø–µ–∫—Ç–∏–≤–∞—Ö —Ä–∞–±–æ—Ç—ã –≤ —Å—Ñ–µ—Ä–µ –≤—ã—Å–æ–∫–∏—Ö —Ç–µ—Ö–Ω–æ–ª–æ–≥–∏–π –ø–æ—Å–ª–µ –ø–æ—Å–µ—â–µ–Ω–∏—è –ó–∞–ø–∏—à–∏—Ç–µ—Å—å –Ω–∞ —É—á–µ–±–Ω—ã–π –ª–∞–≥–µ—Ä—å —Å–µ–≥–æ–¥–Ω—è.

–°—Ä–µ–¥–Ω–∏–π –≤—ã–ø—É—Å–∫–Ω–∏–∫ —É—á–µ–±–Ω–æ–≥–æ –ª–∞–≥–µ—Ä—è –ø–æ—Ç—Ä–∞—Ç–∏–ª –º–µ–Ω–µ–µ —à–µ—Å—Ç–∏ –º–µ—Å—è—Ü–µ–≤ –Ω–∞ –ø–µ—Ä–µ—Ö–æ–¥–Ω—É—é –∫–∞—Ä—å–µ—Ä—É, –æ—Ç –Ω–∞—á–∞–ª–∞ —É—á–µ–±–Ω–æ–≥–æ –ª–∞–≥–µ—Ä—è –¥–æ –ø–æ–∏—Å–∫–∞ —Å–≤–æ–µ–π –ø–µ—Ä–≤–æ–π —Ä–∞–±–æ—Ç—ã.

–ú—ã –∏—Å–ø–æ–ª—å–∑—É–µ–º –∏–Ω–¥–µ–∫—Å–∞—Ü–∏—é –¥–ª—è –≤—ã–±–æ—Ä–∞ –∏ –∏–∑–º–µ–Ω–µ–Ω–∏—è –ø–µ—Ä–≤–æ–≥–æ —ç–ª–µ–º–µ–Ω—Ç–∞ –≤ –Ω–∞—à–µ–º —Å–ø–∏—Å–∫–µ, 99.95. –≠—Ç–æ –∑–Ω–∞—á–µ–Ω–∏–µ –∏–º–µ–µ—Ç –Ω—É–ª–µ–≤—É—é –ø–æ–∑–∏—Ü–∏—é –∏–Ω–¥–µ–∫—Å–∞. –≠—Ç–æ –ø–æ—Ç–æ–º—É, —á—Ç–æ —Å–ø–∏—Å–∫–∏ –∏–Ω–¥–µ–∫—Å–∏—Ä—É—é—Ç—Å—è, –Ω–∞—á–∏–Ω–∞—è —Å –Ω—É–ª—è:

–ù–∞—à –∫–æ–¥ –≤—ã–±–∏—Ä–∞–µ—Ç —ç–ª–µ–º–µ–Ω—Ç –≤ –Ω—É–ª–µ–≤–æ–π –ø–æ–∑–∏—Ü–∏–∏ –∏ —É—Å—Ç–∞–Ω–∞–≤–ª–∏–≤–∞–µ—Ç –µ–≥–æ –∑–Ω–∞—á–µ–Ω–∏–µ –Ω–∞ 104,95. –≠—Ç–æ –Ω–∞ 5 –¥–æ–ª–ª–∞—Ä–æ–≤ –±–æ–ª—å—à–µ –ø—Ä–µ–∂–Ω–µ–≥–æ. –ù–∞—à –∫–æ–¥ –≤–æ–∑–≤—Ä–∞—â–∞–µ—Ç –Ω–∞—à —Å–ø–∏—Å–æ–∫ —Ç–æ–≤–∞—Ä–æ–≤ —Å –ø–µ—Ä–≤–æ–π –∏–∑–º–µ–Ω–µ–Ω–Ω–æ–π —Ü–µ–Ω–æ–π:

–ú—ã –º–æ–∂–µ–º –∏–∑–º–µ–Ω–∏—Ç—å –Ω–∞—à —Å–ø–∏—Å–æ–∫, –¥–æ–±–∞–≤–∏–≤ –ø—è—Ç—å –∫ —Ç–µ–∫—É—â–µ–º—É –∑–Ω–∞—á–µ–Ω–∏—é —Ü–µ–Ω [0]:

price [0] —Å–æ–æ—Ç–≤–µ—Ç—Å—Ç–≤—É–µ—Ç –ø–µ—Ä–≤–æ–º—É —ç–ª–µ–º–µ–Ω—Ç—É –≤ –Ω–∞—à–µ–º —Å–ø–∏—Å–∫–µ (—Ç–æ—Ç –≤ –ø–æ–∑–∏—Ü–∏–∏ –∏–Ω–¥–µ–∫—Å–∞ ).

–ù–∞—à –∫–æ–¥ –≤–æ–∑–≤—Ä–∞—â–∞–µ—Ç —Å–ø–∏—Å–æ–∫ —Å —Ç–µ–º–∏ –∂–µ –∑–Ω–∞—á–µ–Ω–∏—è–º–∏, —á—Ç–æ –∏ –Ω–∞—à –ø–µ—Ä–≤—ã–π –ø—Ä–∏–º–µ—Ä:

Python –∑–∞–º–µ–Ω–∏—Ç—å —ç–ª–µ–º–µ–Ω—Ç –≤ —Å–ø–∏—Å–∫–µ: –∏—Å–ø–æ–ª—å–∑–æ–≤–∞–Ω–∏–µ –ø–æ–Ω–∏–º–∞–Ω–∏—è —Å–ø–∏—Å–∫–∞

–ø–æ–Ω–∏–º–∞–Ω–∏–µ —Å–ø–∏—Å–∫–∞ Python –º–æ–∂–µ—Ç –±—ã—Ç—å –Ω–∞–∏–±–æ–ª–µ–µ Python–∏—á–µ—Å–∫–∏–º —Å–ø–æ—Å–æ–±–æ–º –ø–æ–∏—Å–∫–∞ –∏ –∑–∞–º–µ–Ω—ã —ç–ª–µ–º–µ–Ω—Ç–∞ –≤ —Å–ø–∏—Å–∫–µ. –≠—Ç–æ—Ç –º–µ—Ç–æ–¥ –ø–æ–ª–µ–∑–µ–Ω, –µ—Å–ª–∏ –≤—ã —Ö–æ—Ç–∏—Ç–µ —Å–æ–∑–¥–∞—Ç—å –Ω–æ–≤—ã–π —Å–ø–∏—Å–æ–∫ –Ω–∞ –æ—Å–Ω–æ–≤–µ –∑–Ω–∞—á–µ–Ω–∏–π —Å—É—â–µ—Å—Ç–≤—É—é—â–µ–≥–æ.

–ò—Å–ø–æ–ª—å–∑–æ–≤–∞–Ω–∏–µ –ø–æ–Ω–∏–º–∞–Ω–∏—è —Å–ø–∏—Å–∫–∞ –ø–æ–∑–≤–æ–ª—è–µ—Ç –≤–∞–º –ø–µ—Ä–µ–±–∏—Ä–∞—Ç—å —ç–ª–µ–º–µ–Ω—Ç—ã –≤ —Å—É—â–µ—Å—Ç–≤—É—é—â–µ–º —Å–ø–∏—Å–∫–µ –∏ —Å–æ–∑–¥–∞–≤–∞—Ç—å –Ω–æ–≤—ã–π —Å–ø–∏—Å–æ–∫ –Ω–∞ –æ—Å–Ω–æ–≤–µ –æ–ø—Ä–µ–¥–µ–ª–µ–Ω–Ω–æ–≥–æ –∫—Ä–∏—Ç–µ—Ä–∏–π. –í—ã –º–æ–∂–µ—Ç–µ —Å–æ–∑–¥–∞—Ç—å –Ω–æ–≤—ã–π —Å–ø–∏—Å–æ–∫, –∫–æ—Ç–æ—Ä—ã–π –±—É–¥–µ—Ç —Å–æ–¥–µ—Ä–∂–∞—Ç—å —Ç–æ–ª—å–∫–æ —ç–ª–µ–º–µ–Ω—Ç—ã, –Ω–∞—á–∏–Ω–∞—é—â–∏–µ—Å—è —Å " C " –∏–∑ —Å—É—â–µ—Å—Ç–≤—É—é—â–µ–≥–æ —Å–ø–∏—Å–∫–∞, –Ω–∞–ø—Ä–∏–º–µ—Ä.

–ó–¥–µ—Å—å –º—ã —Å–æ–∑–¥–∞–µ–º –ø—Ä–æ–≥—Ä–∞–º–º—É, –∫–æ—Ç–æ—Ä–∞—è –≤—ã—á–∏—Å–ª—è–µ—Ç 10% —Å–∫–∏–¥–∫—É –Ω–∞ –≤—Å–µ —Ç–æ–≤–∞—Ä—ã –≤ –º–∞–≥–∞–∑–∏–Ω–µ –æ–¥–µ–∂–¥—ã —Å—Ç–æ–∏–º–æ—Å—Ç—å—é –±–æ–ª–µ–µ 50 –¥–æ–ª–ª–∞—Ä–æ–≤. –ú—ã –∏—Å–ø–æ–ª—å–∑—É–µ–º –Ω–∞—à –ø—Ä–µ–¥—ã–¥—É—â–∏–π —Å–ø–∏—Å–æ–∫ —Ü–µ–Ω –Ω–∞ –ø—Ä–æ–¥—É–∫—Ç—ã:

–ó–∞—Ç–µ–º –º—ã –æ–ø—Ä–µ–¥–µ–ª—è–µ–º –ø–æ–Ω–∏–º–∞–Ω–∏–µ —Å–ø–∏—Å–∫–∞ –¥–ª—è –∑–∞–º–µ–Ω—ã —ç–ª–µ–º–µ–Ω—Ç–æ–≤ –≤ –Ω–∞—à–µ–º —Å–ø–∏—Å–∫–µ:

–≠—Ç–æ—Ç —Å–ø–∏—Å–æ–∫ –ø–æ–≤—Ç–æ—Ä—è–µ—Ç—Å—è —á–µ—Ä–µ–∑ " –ø—Ä–∞–π—Å—ã " list –∏ –∏—â–µ—Ç –∑–Ω–∞—á–µ–Ω–∏—è —Å—Ç–æ–∏–º–æ—Å—Ç—å—é –±–æ–ª–µ–µ 50 –¥–æ–ª–ª–∞—Ä–æ–≤. –ù–∞ —ç—Ç–∏ —Ç–æ–≤–∞—Ä—ã –¥–µ–π—Å—Ç–≤—É–µ—Ç —Å–∫–∏–¥–∫–∞ 10%. –ú—ã –æ–∫—Ä—É–≥–ª—è–µ–º –∑–Ω–∞—á–µ–Ω–∏—è —Å–æ —Å–∫–∏–¥–∫–æ–π –¥–æ –¥–≤—É—Ö –¥–µ—Å—è—Ç–∏—á–Ω—ã—Ö –∑–Ω–∞–∫–æ–≤ —Å –ø–æ–º–æ—â—å—é –º–µ—Ç–æ–¥–∞ round ().

–ù–∞—à –∫–æ–¥ –≤–æ–∑–≤—Ä–∞—â–∞–µ—Ç –Ω–∞—à —Å–ø–∏—Å–æ–∫ –Ω–æ–≤—ã—Ö —Ü–µ–Ω:

–°–∫–∏–¥–∫–∞ 10% –±—ã–ª–∞ —É—Å–ø–µ—à–Ω–æ –ø—Ä–∏–º–µ–Ω–µ–Ω–∞ –∫ –∫–∞–∂–¥–æ–º—É —ç–ª–µ–º–µ–Ω—Ç—É .

Python Replace Item in List: Using the For Loop

–í—ã –º–æ–∂–µ—Ç–µ –∑–∞–º–µ–Ω—è—Ç—å —ç–ª–µ–º–µ–Ω—Ç—ã –≤ —Å–ø–∏—Å–∫–µ, –∏—Å–ø–æ–ª—å–∑—É—è Python –¥–ª—è —Ü–∏–∫–ª . –î–ª—è —ç—Ç–æ–≥–æ –Ω–∞–º –ø–æ–Ω–∞–¥–æ–±–∏—Ç—Å—è —Ñ—É–Ω–∫—Ü–∏—è Python enumerate () . –≠—Ç–∞ —Ñ—É–Ω–∫—Ü–∏—è –≤–æ–∑–≤—Ä–∞—â–∞–µ—Ç –¥–≤–∞ —Å–ø–∏—Å–∫–∞: –Ω–æ–º–µ—Ä–∞ –∏–Ω–¥–µ–∫—Å–æ–≤ –≤ —Å–ø–∏—Å–∫–µ –∏ –∑–Ω–∞—á–µ–Ω–∏—è –≤ —Å–ø–∏—Å–∫–µ. –ú—ã –ø–µ—Ä–µ–±–∏—Ä–∞–µ–º —ç—Ç–∏ –¥–≤–∞ —Å–ø–∏—Å–∫–∞ —Å –ø–æ–º–æ—â—å—é –æ–¥–Ω–æ–≥–æ —Ü–∏–∫–ª–∞ for.

–í —ç—Ç–æ–º –ø—Ä–∏–º–µ—Ä–µ –º—ã —Å–æ–±–∏—Ä–∞–µ–º—Å—è –∏—Å–ø–æ–ª—å–∑–æ–≤–∞—Ç—å —Ç–æ—Ç –∂–µ —Å–ø–∏—Å–æ–∫ —Ü–µ–Ω –≤ –Ω–∞—à–µ–º –∫–æ–¥–µ:

–ó–∞—Ç–µ–º –º—ã –æ–ø—Ä–µ–¥–µ–ª—è–µ–º —Ü–∏–∫–ª for, –∫–æ—Ç–æ—Ä—ã–π –ø–æ–≤—Ç–æ—Ä—è–µ—Ç —ç—Ç–æ—Ç list —Å –ø–æ–º–æ—â—å—é —Ñ—É–Ω–∫—Ü–∏–∏ enumerate ():

–ó–Ω–∞—á–µ–Ω–∏–µ " index " —Å–æ—Ö—Ä–∞–Ω—è–µ—Ç –ø–æ–∑–∏—Ü–∏—é –∏–Ω–¥–µ–∫—Å–∞ —ç–ª–µ–º–µ–Ω—Ç–∞. " –¢–æ–≤–∞—Ä " - —ç—Ç–æ –∑–Ω–∞—á–µ–Ω–∏–µ, –∫–æ—Ç–æ—Ä–æ–µ –∫–æ—Ä—Ä–µ–ª–∏—Ä—É–µ—Ç —Å —ç—Ç–æ–π –ø–æ–∑–∏—Ü–∏–µ–π –∏–Ω–¥–µ–∫—Å–∞. –ó–∞–ø—è—Ç–∞—è —Ä–∞–∑–¥–µ–ª—è–µ—Ç –¥–≤–∞ –∑–Ω–∞—á–µ–Ω–∏—è —Å–ø–∏—Å–∫–∞, –≤–æ–∑–≤—Ä–∞—â–∞–µ–º—ã—Ö –º–µ—Ç–æ–¥–æ–º enumerate ().

–ü–æ–ª—É—á–µ–Ω–∏–µ –¥–≤—É—Ö –∏–ª–∏ –±–æ–ª–µ–µ –∑–Ω–∞—á–µ–Ω–∏–π –∏–∑ –º–µ—Ç–æ–¥–∞ –∏–ª–∏ –¥—Ä—É–≥–æ–≥–æ –∑–Ω–∞—á–µ–Ω–∏—è –Ω–∞–∑—ã–≤–∞–µ—Ç—Å—è —Ä–∞—Å–ø–∞–∫–æ–≤–∫–æ–π. –ú—ã "—Ä–∞—Å–ø–∞–∫–æ–≤–∞–ª–∏" –¥–≤–∞ —Å–ø–∏—Å–∫–∞ –∏–∑ –º–µ—Ç–æ–¥–∞ enumerate ().

–ú—ã –∏—Å–ø–æ–ª—å–∑—É–µ–º —Ç–æ –∂–µ —Å–∞–º–æ–µ –ø–æ —Ñ–æ—Ä–º—É–ª–µ –∏–∑ –±–æ–ª–µ–µ —Ä–∞–Ω–Ω–µ–π —Ñ–æ—Ä–º—É–ª—ã –¥–ª—è —Ä–∞—Å—á–µ—Ç–∞ 10% —Å–∫–∏–¥–∫–∏ –Ω–∞ —Ç–æ–≤–∞—Ä—ã —Å—Ç–æ–∏–º–æ—Å—Ç—å—é –±–æ–ª–µ–µ 50 –¥–æ–ª–ª–∞—Ä–æ–≤. –î–∞–≤–∞–π—Ç–µ –∑–∞–ø—É—Å—Ç–∏–º –Ω–∞—à –∫–æ–¥ –∏ –ø–æ—Å–º–æ—Ç—Ä–∏–º, —á—Ç–æ –ø—Ä–æ–∏–∑–æ–π–¥–µ—Ç:

"–ö–∞—Ä—å–µ—Ä–Ω–∞—è –∫–∞—Ä–º–∞ –≤–æ—à–ª–∞ –≤ –º–æ—é –∂–∏–∑–Ω—å, –∫–æ–≥–¥–∞ —è –±–æ–ª—å—à–µ –≤—Å–µ–≥–æ –≤ –Ω–µ–π –Ω—É–∂–¥–∞–ª–∞—Å—å, –∏ –±—ã—Å—Ç—Ä–æ –ø–æ–º–æ–≥–ª–∞ –º–Ω–µ –Ω–∞–π—Ç–∏ –µ–µ. —É—á–µ–±–Ω—ã–π –ª–∞–≥–µ—Ä—å. –ß–µ—Ä–µ–∑ –¥–≤–∞ –º–µ—Å—è—Ü–∞ –ø–æ—Å–ª–µ –≤—ã–ø—É—Å–∫–∞ —è –Ω–∞—à–ª–∞ —Ä–∞–±–æ—Ç—É —Å–≤–æ–µ–π –º–µ—á—Ç—ã, –∫–æ—Ç–æ—Ä–∞—è —Å–æ–æ—Ç–≤–µ—Ç—Å—Ç–≤–æ–≤–∞–ª–∞ –º–æ–∏–º —Ü–µ–Ω–Ω–æ—Å—Ç—è–º –∏ —Ü–µ–ª—è–º –≤ –∂–∏–∑–Ω–∏! "

–í–µ–Ω–µ—Ä–∞, –∏–Ω–∂–µ–Ω–µ—Ä-–ø—Ä–æ–≥—Ä–∞–º–º–∏—Å—Ç –≤ Rockbot

< p> –ù–∞—à –∫–æ–¥ —É—Å–ø–µ—à–Ω–æ –∏–∑–º–µ–Ω—è–µ—Ç —ç–ª–µ–º–µ–Ω—Ç—ã –≤ –Ω–∞—à–µ–º —Å–ø–∏—Å–∫–µ " –ø—Ä–∞–π—Å–∞—Ö " –Ω–∞ –æ—Å–Ω–æ–≤–µ –Ω–∞—à–µ–π —Å–∫–∏–¥–∫–∏.

–ó–∞–∫–ª—é—á–µ–Ω–∏–µ

–í—ã –º–æ–∂–µ—Ç–µ –∑–∞–º–µ–Ω–∏—Ç—å —ç–ª–µ–º–µ–Ω—Ç—ã –≤ —Å–ø–∏—Å–∫–µ Python, –∏—Å–ø–æ–ª—å–∑—É—è –∏–Ω–¥–µ–∫—Å–∏—Ä–æ–≤–∞–Ω–∏–µ —Å–ø–∏—Å–∫–∞, –ø–æ–Ω–∏–º–∞–Ω–∏–µ —Å–ø–∏—Å–∫–∞ , –∏–ª–∏ —Ü–∏–∫–ª for.

–ï—Å–ª–∏ –≤—ã —Ö–æ—Ç–∏—Ç–µ –∑–∞–º–µ–Ω–∏—Ç—å –æ–¥–Ω–æ –∑–Ω–∞—á–µ–Ω–∏–µ –≤ —Å–ø–∏—Å–∫–µ, —Å–∏–Ω—Ç–∞–∫—Å–∏—Å –∏–Ω–¥–µ–∫—Å–∞—Ü–∏–∏ —è–≤–ª—è–µ—Ç—Å—è –Ω–∞–∏–±–æ–ª–µ–µ –ø–æ–¥—Ö–æ–¥—è—â–∏–º. –î–ª—è –∑–∞–º–µ–Ω—ã –Ω–µ—Å–∫–æ–ª—å–∫–∏—Ö —ç–ª–µ–º–µ–Ω—Ç–æ–≤ –≤ —Å–ø–∏—Å–∫–µ, –∫–æ—Ç–æ—Ä—ã–µ —Å–æ–æ—Ç–≤–µ—Ç—Å—Ç–≤—É—é—Ç –∫—Ä–∏—Ç–µ—Ä–∏—é, –∏—Å–ø–æ–ª—å–∑–æ–≤–∞–Ω–∏–µ –ø–æ–Ω–∏–º–∞–Ω–∏—è —Å–ø–∏—Å–∫–∞ —è–≤–ª—è–µ—Ç—Å—è —Ö–æ—Ä–æ—à–∏–º –†–µ—à–µ–Ω–∏–µ. –ù–µ—Å–º–æ—Ç—Ä—è –Ω–∞ —Ç–æ, —á—Ç–æ —Ü–∏–∫–ª—ã for —è–≤–ª—è—é—Ç—Å—è —Ñ—É–Ω–∫—Ü–∏–æ–Ω–∞–ª—å–Ω—ã–º–∏, –æ–Ω–∏ –º–µ–Ω–µ–µ Python–∏—á–Ω—ã, —á–µ–º –ø–æ–Ω–∏–º–∞–Ω–∏–µ —Å–ø–∏—Å–∫–æ–≤.

–í–∞–º –Ω—É–∂–Ω—ã –¥–æ–ø–æ–ª–Ω–∏—Ç–µ–ª—å–Ω—ã–µ —Ä–µ—Å—É—Ä—Å—ã, –∫–æ—Ç–æ—Ä—ã–µ –ø–æ–º–æ–≥—É—Ç –≤–∞–º –∏–∑—É—á–∏—Ç—å Python? –ï—Å–ª–∏ –¥–∞, –≤–∞–º —Å–ª–µ–¥—É–µ—Ç –æ–∑–Ω–∞–∫–æ–º–∏—Ç—å—Å—è —Å –Ω–∞—à–∏–º –†—É–∫–æ–≤–æ–¥—Å—Ç–≤–æ –ø–æ –∏–∑—É—á–µ–Ω–∏—é Python . –≠—Ç–æ —Ä—É–∫–æ–≤–æ–¥—Å—Ç–≤–æ —Å–æ–¥–µ—Ä–∂–∏—Ç —Å–ø–∏—Å–æ–∫ –ª—É—á—à–∏—Ö –∫—É—Ä—Å–æ–≤, –∫–Ω–∏–≥ –∏ —É—á–µ–±–Ω—ã—Ö —Ä–µ—Å—É—Ä—Å–æ–≤, –∫–æ—Ç–æ—Ä—ã–µ –ø–æ–º–æ–≥—É—Ç –≤–∞–º –æ–≤–ª–∞–¥–µ—Ç—å —è–∑—ã–∫–æ–º.