Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I want to combine two lists together

import re
import requests
t=[]
u = []
n = []
k = []
exclude_banned = True
with open("u.txt", "r") as f:
    h = f.readlines()[0:100]
    for sub in h:
        t.append(re.sub('\n', '', sub))
    print(type(t))
    print(t)
    r = requests.post('https://users.roblox.com/v1/usernames/users', json={'usernames': t, 'excludeBannedUsers': exclude_banned})
    print(r.json())
    y = r.json()['data']
    u.extend([f['id'] for f in y])
    n.extend([f['name'] for f in y])
    k.append(f'{u[0]}:{n[0]}\n{u[1]}:{n[1]}')
    print(k)

I want to join all the variables in list u to list n like how they are joined in list k. How would I do this on a massive scale?

I tried the method in list k, but that would be very time-consuming and now all the lists are always the same lengths.
the text in the file is this https://gist.githubusercontent.com/deekayen/4148741/raw/98d35708fa344717d8eee15d11987de6c8e26d7d/1-1000.txt

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Is this closer to what you are expeting?

Iterate through the indices of u and n. Concatenate the elements at the current index in both lists and append to list k.

import re
import requests

t=[]
u = []
n = []
k = []
exclude_banned = True

with open("u.txt", "r") as f:
    h = f.readlines()[0:100]
    for sub in h:
        t.append(re.sub('\n', '', sub))
    print(type(t))
    print(t)
    r = requests.post('https://users.roblox.com/v1/usernames/users', json={'usernames': t, 'excludeBannedUsers': exclude_banned})
    print(r.json())
    y = r.json()['data']
    u.extend([f['id'] for f in y])
    n.extend([f['name'] for f in y])

    # Concatenate elements in u and n using a loop
    for i in range(len(u)):
        k.append(f'{u[i]}:{n[i]}')

    print(k)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading