Python determines whether there are consecutive numbers

Updated on technology 2024-03-19
7 answers
  1. Anonymous users2024-02-07

    s_list=['25','24','23','02','04','06','08','22','23','24','25','02','04','06','08','23','24','25'If the character number to be judged is purely a number, just delete the int.

    end list= List of results.

    t_len=len(s_list)

    z=0for i in range(1,t_len,1):

    if (int(s_list[i])-int(s_list[i-1]))==1:

    if z<=0:

    if z<-1:

    argtemp=

    for j in range(i z-1,i,1):

    end_z=1else:

    z=z 1elif (int(s_list[i])-int(s_list[i-1]))==-1:

    if z>=0:

    if z>1:

    argtemp=

    for j in range(i-z-1,i,1):

    end_z=-1else:

    z=z-1else:

    z=abs(z)

    if z>1:

    argtemp=

    for j in range(i-z-1,i,1):

    end_z=0z=abs(z)

    if z>1:

    argtemp=

    for j in range(t_len-z-1,t_len,1):

    end_for argtemp in end_list:

    for t in argtemp[:-1]:

    print t, print argtemp[-1] results. ###

  2. Anonymous users2024-02-06

    Just look at the ascending order.

    How many in a row?

  3. Anonymous users2024-02-05

    "Qianlong Manuscript One Hundred and Twenty Returns to the Dream of the Red Chamber", in the Xianfeng period, the source title is called "The Dream of the Red Chamber", Yang Jizhen's old collection, also known as "Yang Collection", "Fat Manuscript". Article 78

  4. Anonymous users2024-02-04

    Use it first to group each successive number.

    import itertools

    num_times = [(k, len(list(v)))for k, v in

    The num times thus obtained is the number of consecutive occurrences of each number, num times = [

    Then for each number, count the maximum number of occurrences, this step is relatively simple, just think about it yourself.

  5. Anonymous users2024-02-03

    mylist = [1,1,0,1,1,1,0,0,0,0,1,1,1,1,0,1,0,11,0]

    result = {}

    tmp = none

    for i in mylist:

    if not :

    The new value is 1

    result[i] =

    else:if i == tmp :

    Same as last time, the tmpcount number is added by one, and the maxcount is updated at the same time

    result[tmp]['tmpcount'] = result[tmp]['tmpcount'] +1

    if result[tmp]['maxcount'] result[tmp]['maxcount'] = result[tmp]['tmpcount']

    else: If it is different, the tmpcount of the last digit is zeroed, and the tmpcount of the digit this time is normalized.

    result[i]['tmpcount'] = 1

    result[tmp]['tmpcount'] = 0

    tmp = i

    for j,k in :

    print 'Figures' + str(j) +'The maximum number of consecutive occurrences is' + str(k['maxcount'])

    Try this, it's a bit of a hassle but it should fix the problem.

  6. Anonymous users2024-02-02

    In terms of regular expressions, the regular expression can be written like [0-9], which means that as long as the numbers 0-9 are matched, it means that there are numbers in the string.

  7. Anonymous users2024-02-01

    Judgment of strings:

    isdigit()

    true: Unicode digits, byte digits (single bytes), full-width digits (double bytes), Roman numerals.

    false: Chinese character number.

    error: None.

    isdecimal()

    true: unicode digits, full-width digits (double bytes) false: roman numerals, Chinese numerals.

    error: byte number (single byte).

    isnumeric()

    true: Unicode digits, full-width digits (double bytes), Roman numerals, Chinese numerals.

    false: None.

    error: byte number (single byte).

    Such as s="12335"

Related questions
2 answers2024-03-19

1.Determine if a linked list is intersecting?

Solution 1: Hash table method, maintain a hash table, and iterate through two linked lists respectively. The elements in them are stored in a hash table, and if the elements are duplicated, then the two linked lists intersect. >>>More

11 answers2024-03-19

Obstacle avoidance sensors or ultrasonic sensors (HC-SR04) can be used.

8 answers2024-03-19

How can you tell if a man wants to marry you? Take a look at these points.

14 answers2024-03-19

Don't worry too much, if you're sure you haven't ejaculated, you won't get pregnant. Wait for your period to come with peace of mind (if it has not come for more than a week, it is recommended that you know the accurate answer by then in the test)! You didn't get pregnant this time with 95% accuracy. >>>More

23 answers2024-03-19

To determine whether a girl has a boyfriend, we can observe her reaction to other people's show of affection, her understanding of feelings, her usual life status, whether she often chats with people, and how she dresses. In fact, in life, many friends are looking forward to a very sweet love, but at the beginning of love, you have to understand a person first, if the other party has a boyfriend or girlfriend, this relationship cannot start, but many friends still don't know how to find out whether the other party has a girlfriend or boyfriend, if it is too direct, it seems that they are not very reserved, and some partners are more introverted and shy, Therefore, we can only judge whether the other party already has a boyfriend through some small details, and I will explain it to you from different angles. >>>More