Questions tagged [string-iteration]

20 questions
7
votes
2 answers

Why does Python 'for word in words:' iterate on individual characters instead of words?

When I run the following code on a string words: def word_feats(words): return dict([(word, True) for word in words]) print(word_feats("I love this sandwich.")) I get the output dict-comprehension in letters instead of words: {'a': True, ' ':…
user3564478
  • 71
  • 1
  • 3
2
votes
1 answer

How to update a pandas column with a string constant and number(count)

I have 2 panda columns that looks like so: Request Number Cost Center 1 111 2 133 3 156 NaN 235 NaN 111 NaN …
brodo80
  • 83
  • 3
1
vote
1 answer

C Programming - String Copier

I'm having issues with the following program. #include #include void copy(char *dst, char *src) { // Code for copying a string goes here while(*src != '\0'){ // run loop while last character of src is not terminating…
1
vote
1 answer

What is a properly way to iterate a char* string? Getting "corrupt" values

When I was trying to iterate a number (transformed to binary with bitset library) I managed this solution #include #include void iterateBinary(int num) { char *numInBinary =…
1
vote
3 answers

String Iteration in Python

So the question I was trying to solve is "Print the first 4 letters of name on new line [name = 'Hiroto']" I got a solution, but I was wondering if there was a way to do the same problem using index values to make it work with any name I used.…
1
vote
4 answers

Scala: iterate through every character of a String and use pattern matching

I think what I'm trying to do is pretty obvious. For every character in a string1, print something using patter matching. (I have string2 there because I will use pattern matching of string1 to do something to string 2 and return String 2) For some…
Donat
  • 81
  • 3
  • 12
1
vote
1 answer

How can I ignore certain strings in my string centring function?

N.B: Directly connected to a problem I had a few years ago, but I'd like to resolve the first issue there which wasn't otherwise part of the question, so please don't flag it as a duplicate of my earlier question. I have a string centring function…
AStopher
  • 4,207
  • 11
  • 50
  • 75
0
votes
1 answer

how to prevent the writerow method to iterate through a string

I want to write a string to a csv using writerow but the result I'm getting is not what i want def date_csv(): date_str = pd.Timestamp.today().strftime('%d-%m-%Y') print(date_str) ### output: 16-04-2022 with open("Alert_date.csv",…
0
votes
4 answers

Iterate string to compare an i element to i+1 element python

I have a DNA sequence: seq='AACGTTCAA' I want to count how many letters are equal to the next one. In this example I should get 3 (because of AA-TT-AA). In my first try I found out that this doesn't work, because i is a string and 1 an…
0
votes
2 answers

How do I iterate over every character in a string and multiply it with the place in its string?

I'm doing this coding exercise on codewars.com, and I'm stuck. I'm not looking for a complete solution. Instead, I'm looking to see if my reasoning is correct and if what I'm trying to do is possible. INPUT: so I have a string: "string." And I want…
Stany
  • 3
  • 4
0
votes
3 answers

How can I use a for loop to delete empty spaces at the left and right of a string in JavaScript?

I'm trying to make a homemade trim()'s JavaScript method. I mean, what I want to do can be achieved using trim(): to delete all white spaces from the left and right of the string. I came up with this cumbersome solution; I think it should work, but…
Julio Rodríguez
  • 447
  • 1
  • 8
  • 23
0
votes
1 answer

Python: Append to String N times

My script parses the directory for JSON files and creates tables in the database for each one. I am now working on importing the data from those files. In order to build the SQL query string with a variable length number of columns, I need to…
0
votes
4 answers

How to avoid creating unnecessary lists?

I keep coming across situations where I pull some information from a file or wherever, then have to massage the data to the final desired form through several steps. For example: def insight_pull(file): with open(file) as in_f: lines =…
0
votes
1 answer

While reading multiple files with Python, how can I search for the recurrence of an error string?

I've just started to play with Python and I'm trying to do some tests on my environment ... the idea is trying to create a simple script to find the recurrence of errors in a given period of time. Basically I want to count the number of times a…
silveiralexf
  • 514
  • 1
  • 7
  • 23
0
votes
1 answer

BreakIterator API Java

The documentation for BreakIterator.getWordInstance() has options to use it with the Locale parameter, presumably because different locales' end results may vary for methods like (WordInstance, LineInstance, SentenceInstance, CharacterInstance) But,…
1
2