473,398 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Is there a more efficient way to code this project?

I'm learning Python programming from the Mindmajix training and I just completed classes about lists, tuples, functions and methods. One of the projects following this lecture is to create a program which takes in a list as an input and outputs a corresponding string, as the following example showcases:

Expand|Select|Wrap|Line Numbers
  1. Input: ['bikes', 'cars', 'buses', 'trucks']
Output: bikes, cars, buses, and trucks

So I wrote the code like the below source code:

Expand|Select|Wrap|Line Numbers
  1. def listToString(someList):
  2.     for i in range(len(someList)):
  3.         newString = str(someList[i])
  4.  
  5.         if i == (len(someList)-1):
  6.             print('and ' + str(someList[i]))
  7.         else:
  8.             print(newString, end=', ')
  9.  
  10. someList = ['bikes','cars','buses','trucks']
  11. listToString(someList)
I feel like I didn't use everything (for example, some methods) to solve the problem. Is there a more efficient way to code this project?
Sep 25 '18 #1
0 947

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: storyGerald | last post by:
Recently, I'm interested in writing very efficient code. Problem: there is a sequence { a(0), a(1), ..., a(n-1) } and a very small positive integer k, write an algorithm without using multiply...
1
by: Howie | last post by:
Hi, is there a way to crypt a softwareproject (c++) to confirm only two persons together can compile these project ? Any suggestions ? Thanks in advance, Howie
0
by: IlQlo | last post by:
Hi All. I'm looking for a control to use in VB.NET 2005 that merge a Listview functions with a Treeview. A good example is this one: http://www.codeproject.com/cs/miscctrl/treelistview.asp ...
19
by: aurgathor | last post by:
I use BC 5.02 (long is 32 bit) and I wonder if there's any efficient code that would allow me to left shift 64 bit values that I currently use this way: typedef struct { unsigned long lsLong;...
13
by: gonzlobo | last post by:
Greetings, and happyNewYear to all. I picked up Python a few weeks ago, and have been able to parse large files and process data pretty easily, but I believe my code isn't too efficient. I'm...
10
eWish
by: eWish | last post by:
Will this style of coding cause me some speeding penalties? I am just trying to reduce the number of times I have to write an open function. Naturally, this is just an example. my...
1
by: IvanH | last post by:
In the source code repository of the Container Registry, the code project could not be automatically built after its name was changed in Alibaba Cloud Container Service.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.