I have defined a function that generates ID. I need to increment the numbers every time I call the function.
So I used max() function to find the last largest value stored in the list.
According to the requirements my ID should also consist of a string in front of the integers.
So I have concatenated a string with some numbers which have been stored in a list.
Now my max() does not work,because after concatenating its converted into a alpha-numeric.Please help.I tried splitting the ID but that splits each character.
Following is the function I defined:
#!/usr/bin/python
from DB import *
def Sid():
        idlist = []
        for key in Accounts:
                if Accounts[key]['Acctype'] == 'Savings':
                        idlist.append(Accounts[key]['Accno'])
        if len(idlist) == 0:
                return 1001
    开发者_StackOverflow社区    else:
                abc = max(idlist)
                return abc + 1
EDIT 1: Here is how I have called the function:
  accno = Sid()
  AppendRecord(Accno="SA"+str(accno))
You can strip off the numeric suffix from the string to get a number to increment:
import re
def number_suffix(s):
    """Return the number from the end of the string. """
    match = re.search(r"\d+$", s)
    if match:
        num = int(match.group(0))
    else:
        num = 0
    return num
print number_suffix("AS1001")    # 1001
print number_suffix("AS1")       # 1
print number_suffix("AS")        # 0
then change your function:
idlist.append(number_suffix(Accounts[key]['Accno']))
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论