I have a list of integers s=[1,2,3,4] to be converted to s=['1','2','3','4']
I tried -
s=[1,2,3,4]
-
-
for i in s:
-
str(a[i])
-
-
-
'2'
-
'3'
-
'4'
-
but I lost "1" , can someone explain why I lost "1"? I knew that I could use
My second question is about create a new string -
# I have a string
-
s='hello! world'
-
-
# now I want to have a new string printed as
-
#h
-
#he
-
#hel
-
#...
-
-
# I tried
-
-
for i in len(s):
-
stringA=a[i]
-
stringA+=a[i+1]
-
print stringA
-
#but it did not work
-
-
6 1884
I have a list of integers s=[1,2,3,4] to be converted to s=['1','2','3','4']
I tried -
s=[1,2,3,4]
-
-
for i in s:
-
str(a[i])
-
-
-
'2'
-
'3'
-
'4'
-
but I lost "1" , can someone explain why I lost "1"? I knew that I could use
replace a[i] with i... i means the the elements in the list... not their index.. : -
>>> s=[1,2,3,4]
-
>>> [str(i) for i in s]
-
['1', '2', '3', '4']
-
>>> s=[str(i) for i in s]
-
thank you very much.
I just added second question.
for the hello world program u can try this : -
for i in range(len(s)):
-
print s[0:i+1]
-
i just read the book some days ago that I could use [:::] to get this.
Thank you very much for helping me out.
for i in len(s):
stringA=a[i]
stringA+=a[i+1]
print stringA
your code did not work because u havent defined the variable 'a' anywhere.... so the interpreetr doesnt know what to assign to the variable 'stringA'
regards
rhitam
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Gordon Airport |
last post by:
Has anyone suggested introducing a mutable string type (yes, of course)
and distinguishing them from standard strings by the quote type - single
or double? As far as I know ' and " are currently interchangeable in all
circumstances (as long as they're paired) so there's no overloading to
muddy the language. Of course there could be some interesting problems
with current code that doesn't make a distinction, but it would be dead
easy to fix...
|
by: NickB |
last post by:
Please could someone tell me what is wrong.
Ther error is:
An unhandled exception of type 'System.NullReferenceException' occurred in
microsoft.visualbasic.dll
Additional information: Object variable or With block variable not set.
I am trying to print the contents of a list box on another form.
This is the sub, and the highlighted line is where it is falling over.
|
by: John Young |
last post by:
Hi I have just started messing about with generics.
I have done this..
List<string> myList = new List<string>();
I've added strings to the list...
But now I want to clear the list completely...
myList.RemoveAll( ??? );
|
by: Roger Lord |
last post by:
I am constructing a string in my program and then trying to use
it to get the value of an integer variable whose label looks like
that string. I can't figure out how to do it. For example:
Dim aXYZ As Integer = 5
Dim myString As String
Dim myResults As Integer
myString = "aXYZ"
|
by: Jeff |
last post by:
for your info - I'm a newbe.
Code is at the bottom.
Access dbase (each form ca. 10 KB) if my explanations are not enough
(probably they aren't).
-- access 97 - http://www.lokalny.net/Source97.zip
-- access 200 - http://www.lokalny.net/Source2000.zip
------
Im trying to change code - just trying to learn something. But nothing seems
| |
by: Tripper |
last post by:
Which is the better way to go and why?
//trivial example
List<string> strings = GetStrings();
foreach (string s in strings)
{
// some operation;
}
strings.ForEach(
|
by: simon |
last post by:
hello,
new to vb.net, have a few questions about DataGrid. I have a dataGrid
that is working pulling a dataset back from a stored proc and binding
to the datagrid for display
the datagrid's first column is a textbox(TemplateColumn), the other 3
columns are just display(BoundColumn).
(1) if the value of the textbox is 0, then i'd like to change it null,
so the box is empty
|
by: arnuld |
last post by:
i was doing exercise 4.3.1 - 4.29 of "C++ Primer 4/e" where authors,
with "run-time shown", claim that C++ Library strings are faster than
C-style character strings. i wrote the same programme in C & hence
found that claim of the authors is *partial*. If we use C-style strings
in C++ instead of Library String class, then they are slow but if write
the same programme in C then C strings are "faster" than both C++
Library strings & C-style...
|
by: gazgump |
last post by:
I'm doing some practice questions and cant seem to work out these collection probelms think i need to use iterator or a while loop but cant seem to get them to work - dont really know how i'd go about getting the highest value in the collection any help would be appreciated, even just learning from the answers would be a lot of help.. cheers - see below
Given a list of integers and an integer variable declared like this:
List<Integer>...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |