Jump to content

Splitting Characters from Words (Python)

Br3tt96

So I'm attempting to solve a problem where I have to basically swap the first three letters of both words. Would splitting be my best option? I have it hard coded atm, for basically adding the 6 characters in different order, but I'm sure that won't achieve full credit. 

 

Spoiler

Enter the first word: cherry

Enter the second word: celery

 

The new word is: celrry cheery

 

 

Spoiler

 

LTT's Fastest single core CineBench 11.5/15 score on air with i7-4790K on air

Main Rig

CPU: i7-4770K @ 4.3GHz 1.18v, Cooler: Noctua NH-U14S, Motherboard: Asus Sabertooth Mark 2, RAM: 16 GB G.Skill Sniper Series @ 1866MHz, GPU: EVGA 980Ti Classified @ 1507/1977MHz , Storage: 500GB 850 EVO, WD Cavier Black/Blue 1TB+1TB,  Power Supply: Corsair HX 750W, Case: Fractal Design r4 Black Pearl w/ Window, OS: Windows 10 Home 64bit

 

Plex Server WIP

CPU: i5-3570K, Cooler: Stock, Motherboard: ASrock, Ram: 16GB, GPU: Intel igpu, Storage: 120GB Kingston SSD, 6TB WD Red, Powersupply: Corsair TX 750W, Case: Corsair Carbide Spec-01 OS: Windows 10

 

Lenovo Legion Laptop

CPU: i7-7700HQ, RAM: 8GB, GPU: 1050Ti 4GB, Storage: 500GB Crucial MX500, OS: Windows 10

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

(let x be a string variable)

 

a = x.split()

z = y.split()

then take the first three from the list a then replace the first three in list z with the first three in list a and vice versa? then remove spaces

not sure, as I don't have much python experiance.

Link to comment
Share on other sites

Link to post
Share on other sites

Look into string concatenation and array splicing in Python. You can do it in a single line with those two language features.

 

To get you started:

 

x = 'cherry'
a, b = x[:3], x[3:]


would split cherry into 'che' and 'rry'.
If you do the same with celery and concatenate them appropriately, you should be able to get your swapping working just fine.

Link to comment
Share on other sites

Link to post
Share on other sites

exactly what i needed!!!

Spoiler

 

LTT's Fastest single core CineBench 11.5/15 score on air with i7-4790K on air

Main Rig

CPU: i7-4770K @ 4.3GHz 1.18v, Cooler: Noctua NH-U14S, Motherboard: Asus Sabertooth Mark 2, RAM: 16 GB G.Skill Sniper Series @ 1866MHz, GPU: EVGA 980Ti Classified @ 1507/1977MHz , Storage: 500GB 850 EVO, WD Cavier Black/Blue 1TB+1TB,  Power Supply: Corsair HX 750W, Case: Fractal Design r4 Black Pearl w/ Window, OS: Windows 10 Home 64bit

 

Plex Server WIP

CPU: i5-3570K, Cooler: Stock, Motherboard: ASrock, Ram: 16GB, GPU: Intel igpu, Storage: 120GB Kingston SSD, 6TB WD Red, Powersupply: Corsair TX 750W, Case: Corsair Carbide Spec-01 OS: Windows 10

 

Lenovo Legion Laptop

CPU: i7-7700HQ, RAM: 8GB, GPU: 1050Ti 4GB, Storage: 500GB Crucial MX500, OS: Windows 10

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×