Python Forum
Credit card number redacting script
Thread Rating:
  • 4 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Credit card number redacting script
#6
(Jan-15-2019, 02:40 AM)Drone4four Wrote: In order for a function to properly return value, when the function is called, it’s necessary to declare it as a variable. I see now.

Actually, defining a variable is not necessary, the return statement is necessary. This works just fine:

def three():
     return 5
(Jan-15-2019, 02:40 AM)Drone4four Wrote: But seeing someone demonstrate enumerate in the context of my fake credit card redaction task here I think would really help me understand the concept better.

def ccredact(card_string):
    redacted = []
    for letter_index, letter in enumerate(card_string):
        if letter_index < 12:
            redacted.append('*')
        else:
            redacted.append(letter)
        if letter_index in (3, 7, 11):
            redacted.append('-')
    return ''.join(redacted)
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Credit card number redacting script - by Drone4four - Jan-01-2019, 06:10 PM
RE: Credit card number redacting script - by ichabod801 - Jan-15-2019, 02:51 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Music Python Script Repeating Number When Saving Facebook Photos ThuanyPK 2 269 May-13-2024, 10:59 PM
Last Post: ebn852_pan
  Having strange results from an RFID HID card reader - I'm stuck orbisnz 1 1,594 Mar-28-2022, 08:20 AM
Last Post: Larz60+
  SQL wild card use hammer 3 1,379 Jan-07-2022, 02:17 PM
Last Post: hammer
  Validating credit card frequency 8 4,410 Nov-05-2018, 07:36 PM
Last Post: frequency
  individual's ID card number in python danpek 2 3,868 Jun-14-2018, 04:07 PM
Last Post: DeaD_EyE
  Prime number Script Problem Codezters 4 4,172 Jul-21-2017, 03:07 AM
Last Post: Larz60+
  RAW IO disk access for SD Card shift838 1 8,686 Feb-27-2017, 03:35 AM
Last Post: Larz60+
  "Card Dealing" Python code 2.7 Paradoxalis 3 6,783 Nov-17-2016, 11:32 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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