python - How to split a returned integer: (Trying to find recurrences within it) -


this might simple question, it's giving me lot of trouble.

code:

def search_likes(passed_list): #passed_list contains links find below     print("found",len(passed_list),"videos, finding likes.")     x = 0     print("currently fidning likes video",x,".")     while x< len(passed_list):          likefinder = []         r = requests.get(passed_list[0])         soup= beautifulsoup(r.content, 'lxml')         d_data = soup.find_all("span", {"class": "yt-uix-button-content"}) #location of number i'm looking         likefinder.append(d_data)         str1= ''.join(str(e) e in likefinder) #converts list string         likenumber= (int(''.join(list(filter(lambda x: x.isdigit(), str1))))) #removes string , leaves integers           x+=1 #count 

output:

845528455314391440

i split code begins repeat itself. ie ['84552','8455314391440']

if have insight on how appreciate it!

thanks, ben

given string s containing numbers, , number n size of repetition want find, can do:

s.find(s[:n], n) 

this finds index of first occurrence, after start of string, equal first n characters of string. example:

s = str(845528455314391440) n = 3 r = s.find(s[:n], n) print(r) 

output:

5 

you can use split string , turn parts numbers:

a, b = int(s[:r]), int(s[r:]) print(a, b) 

output:

84552 8455314391440 

all combined function, accounting numbers without repitition:

def split_repeat(i, n):     s = str(i)     r = s.find(s[:n], n)     if r == -1:         return none     else:         return int(s[:r]), int(s[r:]) 

usage:

print(split_repeat(845528455314391440, 3)) print(split_repeat(876543210, 3)) print(split_repeat(1122, 3)) 

output:

(84552, 8455314391440) none none 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -