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

>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)

Leave a Reply