i have a problem im trying to solve in python but I'm not sure if its possible

ive got lists of data
one line that is the full name Eg. name:John Doe and the line below is a the user ID Eg. userID:jdoe
i have both of those being made into sperate strings
but what i need to do is make the user ID string Mixed case instead of lower.
so instead of jdoe it would be JDoe
copying the case that was user from the full name

the other issue is the user ID can be differnt styles depending on the user so they could be


i don't realy get your question but i thing this can do.
first creat a loping contract that loop over the individual letter in the string using

    for i in userID
       """ code here""" 

than use i.upper() to change the letter you want to upper.
By the way there are more effecient ways of doing this but for learning perposes you can try this

just to clarify
i want my user ids to take the capitalization from the full name string.
i only get one user per userID but some names have them in a different style so the types of userID's i can possible get are like:

since the fullname has a capital J and a capital D i need to find a way to make those chars capital in which ever user ID i capture
so they would look like:


One way to do this:

def make_userid(user):
    first, last = user.split()
    user_id = first[0] + last
    return user_id

user = "John Doe"

user_id = make_userid(user)

print(user_id)  # JDoe
result = ''
for i in userID:
    if i.upper() in userNAME:
        result += i.upper()
        result += i

This will work and i belive it is easy to understand. Let us know what happens ok.

Looks like our friend otengkwaku is on the right track. You have to rebuild a new ID string.
The only problem with his code are names like "Matt Mummert"

Edited 3 Years Ago by vegaseat

Maybe this would help you. It does not generate the userid's, since you already have them, but it capitalize some parts of them:

def mkusr():
    name="John Doe"
    userid, rez, names=['jdoe','johndoe', 'jdoe02', 'johndoe02'], [], name.split()
    for i in userid:
        i = i.capitalize()
        for j in names:
            if j.lower() in i:
                i = i.replace(j.lower(), j)
    print userid
    print rez

As an output:

['jdoe', 'johndoe', 'jdoe02', 'johndoe02']
['JDoe', 'JohnDoe', 'JDoe02', 'JohnDoe02']
This article has been dead for over six months. Start a new discussion instead.